python - 如何在python中循环使用wget进行下载

标签 python loops wget

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

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']])

关于python - 如何在python中循环使用wget进行下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39314891/

相关文章:

python - 如何在Python中的字典列表上进行插入排序?

python - 在 python 脚本中将参数传递给 scrapy spider

ruby - 关于表行和循环的 Watir 问题

bash - curl -C, --continue-at 在管道标准输出时工作吗?

linux - wget 从 ftp 中选择样本?

curl - 无法通过 wget 使用 Jenkins API token

Python 数组求和与 MATLAB

python - 为集合容器定义 __str__ 和 __repr__

r - 如何排列从 for 循环创建的 ggplots

loops - go lang + snmp in lool(错误连接处理)