第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 python 中,我有 100 個(gè)頁(yè)面的鏈接并想將它們保存為 html

在 python 中,我有 100 個(gè)頁(yè)面的鏈接并想將它們保存為 html

繁花不似錦 2023-04-18 17:29:50
里面有 100 頁(yè)的鏈接(links.txt)這是我到目前為止的代碼(它只保存一頁(yè))但是缺少保存所有 99 頁(yè)的部分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貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

您需要在循環(huán)時(shí)為文件指定不同的名稱(chēng):


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)

這將在每個(gè)文件名的末尾附加一個(gè)數(shù)字。


查看完整回答
反對(duì) 回復(fù) 2023-04-18
  • 1 回答
  • 0 關(guān)注
  • 136 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)