无法找到beautifulsoup解析器中已经存在的数据

问题描述 投票:-1回答:1

我正在从newegg网站上抓取产品详细信息。我尝试从右侧边栏刮取价格。在汤中以lxml格式存在(请参见图1),但是当我尝试从汤中使用find方法获取边栏时,它不会显示所有数据(请参见图2)。

这是什么原因?

**图像和代码在下面

Image 1Image2

headers = {"User-agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"}
url = link
data = re.get(url,headers=headers)
soup = bs4.BeautifulSoup(data.content, 'lxml')

title = soup.find("div", {"class":"wrapper"}).text
price = soup.find("div", {"id":"continueReal"})
python beautifulsoup lxml
1个回答
0
投票

您可以从具有价格的itemprop属性中提取

import requests

r = requests.get('https://www.newegg.com/black-msi-gl-series-gl73-9rcx-030-gaming-entertainment/p/N82E16834155245?Item=N82E16834155245&Tpk=N82E16834155245')
soup = bs(r.content, 'lxml')
print(soup.select_one('[itemprop=price]')['content'])
print(soup.select_one('#grpDescrip_34-155-245').text.strip())

或者尝试使用相同的xhr请求页面,可以在广告网络标签中找到。

© www.soinside.com 2019 - 2024. All rights reserved.