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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

遍歷索引目錄的服務(wù)器 URL 并讀取文件

遍歷索引目錄的服務(wù)器 URL 并讀取文件

哈士奇WWW 2023-06-06 17:26:50
http服務(wù)器上有一個目錄,其url是http://somehost/maindir/recent/。這個“最近”目錄包含 50 個 zip 子目錄。我可以讀取一個 zip 文件 zfile = "http://somehost/maindir/recent/1.zip" with RemoteZip(zfile) as zip:        for zip_info in zip.infolist():            data = zip.read(zip_info.filename)但是我不知道要遍歷“http://somehost/maindir/recent/”并從每個 zip 中讀取數(shù)據(jù)。我嘗試了 glob、os.join、os.walk 但在靜脈中。我想要這樣的東西:for zfile in baseurl: //unable to do this line.    with RemoteZip(zfile) as zip:        for zip_info in zip.infolist():                data = zip.read(zip_info.filename)
查看完整描述

1 回答

?
月關(guān)寶盒

TA貢獻1772條經(jīng)驗 獲得超5個贊

您無法直接獲取目錄列表,因為它是負(fù)責(zé)返回響應(yīng)的 HTTP 服務(wù)器,在某些情況下,您將獲得一個 HTML 頁面,顯示指向“目錄”內(nèi)所有文件的鏈接,如您的情況“http:/ /somehost/maindir/recent/" 將以 html 格式列出最近目錄中的所有 zip 文件。


一種解決方案可能是使用 Beautifulsoup 解析該 html 頁面并從該“最近”目錄頁面獲取所有指向 zip 文件的鏈接。


from bs4 import BeautifulSoup

import requests


url = 'http://somehost/maindir/recent/'



def get_files(url):

   page = requests.get(url).text

  

   soup = BeautifulSoup(page, 'html.parser')

   return [url + '/' + node.get('href') for node in soup.find_all('a') if 

           node.get('href').endswith('.zip')]

file_links = get_files(url)

for zfile in file_links:

    with RemoteZip(zfile) as zip:

        for zip_info in zip.infolist():

            data = zip.read(zip_info.filename)


查看完整回答
反對 回復(fù) 2023-06-06
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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