我想使用網路報廢從檔案 https://archive.ics.uci.edu/ml/machine-learning-databases/00380/YouTube-Spam-Collection-v1.zip中獲取資料
如何在 python中使用請求來做到這一點?
uj5u.com熱心網友回復:
您可以使用此示例如何使用requests內置zipfile模塊加載 zip 檔案:
import requests
from io import BytesIO
from zipfile import ZipFile
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/00380/YouTube-Spam-Collection-v1.zip"
with ZipFile(BytesIO(requests.get(url).content), "r") as myzip:
# print content of zip:
# print(myzip.namelist())
# print content of one of the file:
with myzip.open("Youtube01-Psy.csv", "r") as f_in:
print(f_in.read())
印刷:
b'COMMENT_ID,AUTHOR,DATE,CONTENT,CLASS\n
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/431622.html
標籤:python-3.x 网页抓取 蟒蛇请求 数据集
下一篇:為BS4網路抓取獲取“無”
