使用wg下载文件

2024-10-01 00:27:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从网页下载fits文件。我使用的是-iwget选项:我将下载文件存储在列表.txt包含URL1,URL2的文件。。。然后呢

$ wget -i list.txt

你知道有没有可能使用python脚本做同样的事情? 谢谢。在


Tags: 文件txt脚本网页列表选项wget事情
3条回答
with open('list.txt') as my_list:
    for url in my_list:
        wget.download(url)

如果您获得SSL:CERTIFICATE\u VERIFY\u失败:

import wget
import ssl

ssl._create_default_https_context = ssl._create_unverified_context
with open('list.txt') as my_list:
    for url in my_list:
        wget.download(url)

使用操作系统库:

^{pr2}$

假设文件每行包含一个URL,则可以执行以下操作:

import urllib2
with open('list.txt') as my_list:
    for line in my_list:
        response = urllib2.urlopen(line)
        html = response.read()
        # now process the page's source

相关问题 更多 >