[英]Web scraping the console of a web page using python
所以我有這段代碼 web 抓取某個站點並打印出它在該特定網頁上找到的內容。 我對此很陌生,所以我的問題是如何僅從控制台收集數據,就像圖片中看到的那樣。
這是到目前為止的代碼,感謝您的幫助
導入請求
url = '網址在這里'
r = requests.get(url)
打印(r.text)
下面是一些收集output的方法:
如果數據非常小且格式正確,例如每個 URL 僅 1 行,您可以從控制台打印中復制 output。
如果數據很大,我假設這是您的情況,您可以將 output 寫入文件。
import requests
url = 'url goes here'
r = requests.get(url)
print(r.text)
with open('/path/to/file.txt', 'w', encoding='utf-8') as f:
f.write('r.text')
above example are using a txt file, you can also write the output into a.xml file or.html file, any format that is more convenient to re-use for you, like docx, excel, csv, json, etc.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.