我想知道是否有任何方法可以使用 python 從某些 url 獲取文本。
例如,從這個https://www.ixbt.com/news/2022/04/20/160-radeon-rx-6400.html
先感謝您。
uj5u.com熱心網友回復:
您可以使用以下命令在 python 中進行網路抓取BeautifulSoup:
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = "https://www.ixbt.com/news/2022/04/20/160-radeon-rx-6400.html"
html = urlopen(url).read()
soup = BeautifulSoup(html, features="html.parser")
text = soup.get_text()
之后,您可以將提取的文本保存到文本檔案中:
text_file = open("webscrap.txt", "w", encoding="utf-8")
text_file.write(text)
text_file.close()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460459.html
上一篇:如何在不使用Sanctum或Passport的情況下在Laravel9中生成訪問令牌
下一篇:將資料從一個頁面發送到另一個顫振
