python 如何循环使用wget 一个一个下载

How to download using wget one by one in a loop in python

我编写了以下从页面下载的代码:

import urllib2,os
    from bs4 import BeautifulSoup

    page = urllib2.urlopen('http://somesite.com')
    soup = BeautifulSoup(page)

    for a in soup.find_all('a', href=True):
        if "tutorials" in a['href']:
            os.system('wget ' + a['href'])

问题出在上面的命令上,它从页面上下载了所有链接。我想一个一个地下载视频。那可能吗?请帮助我。

使用 subprocess.call 模块代替 os.system。

subprocess.call(['wget' , a['href']])

我来晚了,但我认为这可能对某些人有所帮助。如何在单独的函数中使用 os.system() 并在循环中每次调用它?

喜欢:

def helper(arg):
   if(os.system(arg) == 0):
        print(arg," completed")
        return None

for link in links:
    helper("wget "+link)

我认为这将确保逐一下载。 如果我错了,请纠正我。谢谢!