使用python脚本(Windows)中的wget命令



我在文件夹中下载了wget,并运行以下命令:

wget.exe -i link_goes_here.mp4 -c -nc -P "K:FolderofSavedvideos"

有没有什么方法可以让它在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 happenedn')
continue

如果我理解您在命令行中键入该命令。您可以使用子流程库来执行此操作。

import subprocess
command = ["wget.exe", "-i", "https://link.com/video.mp4", "-c", "-nc", '"K:FolderofSavedvideos"']
print(link)
process = subprocess.Popen(command)

我相信这就是你的要求,如果不告诉我,我可以帮助:(

就像@Quintin说的

import subprocess
command = ["wget.exe", "-i", link, "-c", "-nc", '"K:FolderofSavedvideos"']
print(link)
process = subprocess.Popen(command)

而是使用-i之后的链接。

使用子流程。Popen((执行终端命令。

最新更新