我正在嘗試獲取圖像的 src,但我返回的 HTML 代碼與網(wǎng)站上顯示的 HTML 代碼不同。from bs4 import BeautifulSoupimport requestsheaders = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"}url = "https://www.amazon.de/ASUS-Advanced-Grafikkarte-Speicher-Displayport/dp/B07VM9V59H/ref=sr_1_20?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=1928HLQLPKSTH&keywords=nvidia&qid=1585480732&s=computers&sprefix=nvid%2Ccomputers%2C171&sr=1-20"response = requests.get(url, headers=headers).textsoup = BeautifulSoup(response, 'lxml')title = soup.select("#productTitle")[0].get_text().strip()imgdata = soup.find_all('img', {"alt":title})print(imgdata)
1 回答

RISEBY
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
這是因?yàn)樗麄儗D像編碼為 base64,一旦您打開(kāi)頁(yè)面,就會(huì)在瀏覽器上呈現(xiàn)該圖像。
您可以從另一個(gè)屬性獲取圖像 url,如下所示:
img_url = imgdata[0].attrs['data-old-hires']
- 1 回答
- 0 關(guān)注
- 158 瀏覽
添加回答
舉報(bào)
0/150
提交
取消