里面有 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
提交
取消