繁体   English   中英

Python Web 抓取多个网址 Output ZCC8D68C551C4A4AFDED7

[英]Python Web scraping multiple URLs Output CSV

我今天从字面上开始使用 python,我设法得到一个 url 来使用 python 显示数据。

import requests

URL = "https://gateway.pinata.cloud/ipfs/QmUJrnabRCMLsnvXNryojLWcysc4WwJCLqWYvJcWADfZFo/chadsJSON/1.json"
page = requests.get(URL)

print(page.text)

我需要查找多个 url(如上,但编号为 1-upto 10,000)并将其保存为 csv,每个 url 数据位于一个单元格中

请任何人都可以制作我可以运行的 python 代码。

这是一个非常简单的答案,但在您的情况下将非常有用,尽管您仍然需要做一些工作才能达到所需的 output。

这是使用for循环发送从 0 到 100 的请求的方法: For Loop

import requests

for i in range(100):
    URL = f"https://gateway.pinata.cloud/ipfs/QmUJrnabRCMLsnvXNryojLWcysc4WwJCLqWYvJcWADfZFo/chadsJSON/{str(i)}.json"
page = requests.get(URL)

print(page.text)

And to store the data in a CSV file, I advice you to use csv library which is really helpful in that, you can read more in its documentation: https://docs.python.org/3/library/csv.html

import csv
with open('file.csv', 'a+', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(["COL1", "COL2"])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM