我一直在嘗試使用 bs4 抓取網頁,但是,HTML 似乎與我在 Chrome 中使用“查看頁面源”時看到的不匹配。作為該領域的新手,非常感謝任何有關此方面的指導!詳情如下:
此處的目標網頁示例和使用的代碼如下所示。
import requests
from bs4 import BeautifulSoup
my_url = 'https://finance.yahoo.com/m/63c37511-b114-3718-a601-7e898a22439e/a-big-tech-encore-and-twitter.html'
response = requests.get(my_url)
doc = BeautifulSoup(response.text, "html.parser")
with open("output1.html", "w") as file:
file.write(str(doc))
在我的瀏覽器 (Chrome) 中查看頁面源代碼時,以下代碼段包含在 html 中:
"siteAttribute":"ticker=\"GOOGL;AAPL;PYPL;TWTR\"
但是,當查看上面代碼的檔案輸出時,siteAttribute
已經改變并且不再具有相同的資訊。相反,它顯示:
"siteAttribute":"wiki_topics=\"Big_Tech;Apple_Inc.;Facebook;
上網查了一下,不知道是什么原因造成的?提前致謝。
uj5u.com熱心網友回復:
如果您從 chrome devtools 的彈出框選項卡中單擊檢查,然后按 ctrl F 并粘貼siteAttribute":"ticker=\"GOOGL;AAPL;PYPL;TWTR\
,您將看到所需的結果位于腳本標記下。請看這里的截圖
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/468774.html
標籤:Python html 谷歌浏览器 网页抓取 美丽的汤
下一篇:想從網頁中提取表格資訊