里面有 100 页的链接(links.txt)这是我到目前为止的代码(它只保存一页)但是缺少保存所有 99 页的部分import requestsimport urllib.request, urllib.error, urllib.parse with open('links.txt', 'r') as links: for link in links: response = urllib.request.urlopen(link) webContent = response.read() f = open('obo-t17800628-33.html', 'wb') f.write(webContent) f.close
1 回答
吃鸡游戏
TA贡献1829条经验 获得超7个赞
您需要在循环时为文件指定不同的名称:
import requests
import urllib.request, urllib.error, urllib.parse
with open('links.txt', 'r') as links:
for idx, link in enumerate(links):
response = urllib.request.urlopen(link)
webContent = response.read()
with open('obo-t17800628-33.html' + str(idx), 'wb') as fout:
fout.write(webContent)
这将在每个文件名的末尾附加一个数字。
添加回答
举报
0/150
提交
取消