![](/img/trans.png)
[英]Storing a python script output to a variable in linux and run a wget command
[英]Have a wget command in python script (Windows)
我在文件夾中下載了wget ,然后運行以下命令:
wget.exe -i link_goes_here.mp4 -c -nc -P "K:\Folder\of\Saved\videos"
有什么辦法可以讓這個在 Python 腳本中運行,這樣我就不必手動運行這個命令了嗎? 我有一個 Python 腳本,它具有:
print(link)
我想知道是否有任何方法可以讓 wget 在打印發生后執行下載?
這是我正在使用的腳本:
while True:
try:
file=open('recent.txt','a', buffering=1)
try:
response=[]
response=requests.get(API_link,proxies=proxies,headers=headers).text.split('[')[1].split(']')[0]
response=response.split(',')
for i in response:
temp=''
temp=i.split('"')[1].split('"')[0]
if temp not in list_:
link=''
link=starting_part+temp+".mp4"
print(link)
file.write(link)
file.write('\n')
list_+=[temp]
file.close()
sleep(5)
except:
continue
print(len(list_))
except requests.ConnectionError:
continue
except requests.exceptions.Timeout:
continue
else:
#print('Something happened\n')
continue
如果我明白您在命令行中鍵入該命令。 您可以使用子流程庫來執行此操作。
import subprocess
command = ["wget.exe", "-i", "https://link.com/video.mp4", "-c", "-nc", '"K:\Folder\of\Saved\videos"']
print(link)
process = subprocess.Popen(command)
我相信這就是您要問的問題,如果不告訴我,我可以提供幫助:)
就像@Quintin 說的
import subprocess
command = ["wget.exe", "-i", link, "-c", "-nc", '"K:\Folder\of\Saved\videos"']
print(link)
process = subprocess.Popen(command)
而是在 -i 之后使用鏈接。
使用 subprocess.Popen() 執行終端命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.