我想提取所有审查细节,如名称、日期和审查数据等,用于产品blueair的以下网站。 https://www.costco.com/blueair-healthprotect-7410i-hepasilent-ultra-air-purifier-with-germshield.product.100750915.html 看起来它是隐藏的并且使用了javascript
import requests
from bs4 import BeautifulSoup
from requests_html import HTMLSession
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '\
'AppleWebKit/537.36 (KHTML, like Gecko) '\
'Chrome/75.0.3770.80 Safari/537.36'}
URL = 'https://www.costco.com/blueair-healthprotect-7410i-hepasilent-ultra-air-purifier-with-germshield.product.100750915.html'
httpx = requests.get(URL, headers=headers)
# print(httpx.text)
soup = BeautifulSoup(httpx.content,'html.parser')
for data in soup.findAll('span', class_='bv-content-datetime-stamp'):
print(data)
这不是一个静态的网页,所以您需要做的是分析请求和响应。这里是一个简化的方法来处理您的案例
F12
打开devtools,转到名为Network
的选项卡,然后刷新页面李>Network
,然后按<C-f>
打开搜索窗格,键入一条评论,如“我购买了一架Blueair”,然后按<Enter>
李>batch.json
,检查它,您将知道在哪里可以获得所需的数据李>接下来可以做的是分析请求URL和api参数,然后尝试将请求发送到该api。如果一切顺利,您应该能够得到相同的
batch.json
使用具有限制的API获取所有评论
这些是您可以调整的查询参数
相关问题 更多 >
编程相关推荐