我想从百年灵网站上的产品页面中搜寻各种信息。你知道吗
示例页:https://www.breitling.com/gb-en/watches/navitimer/b01-chronograph-46/AB0127211C1A1/
我有困难刮手表的表带材料在下拉菜单上面的“添加到包”按钮('钢1.4435'在例子的情况下)。你知道吗
我想要的具体元素是:
<small class="dd-selected-description dd-desc dd-selected-description-truncated">Steel 1.4435</small>
但是,这不会在对GET请求的响应中返回。距离<small>
标记最近的元素是带有id='strap-selector-list'
的<div>
元素。你知道吗
但是,当调用soup.find(id='strap-selector-list')
时,它将<div>
显示为不包含任何内容。你知道吗
import requests
from bs4 import BeautifulSoup
url = 'https://www.breitling.com/gb-en/watches/navitimer/b01-chronograph-46/AB0127211C1A1/'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
soup.find(id='strap-selector-list')
退货
<div id="strap-selector-list"></div>
我怎样才能得到里面的信息(当你打开检查器时会显示出来?)你知道吗
Screenshot of page with inspector open highlighting areas of interest
我试过的:
headers = {'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
'cache-control': 'max-age=0',
'dnt': '1',
'referer': 'https://www.breitling.com/gb-en/watches/navitimer/?search%5Bref%5D=&search%5Bsorting%5D=newest',
'sec-fetch-mode': 'navigate, same-origin, cors',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
r = requests.get(url, headers=headers)
已检查XHR请求。页面加载时只有3个。一个是关于收银台的状态,一个是关于零售商的信息,比如他们的商店位置,另一个是状态.php它给出了404错误。你知道吗
如果单击下拉菜单,则不会发送XHR请求。你知道吗
如果单击下拉菜单中的任何项目,则会转到该项目的产品页。
使用不同的解析器,例如。html.parser语法分析器没有区别
session = requests.Session()
并在有headers=headers
和没有headers=headers
的情况下执行r = session.get(url)
也不起作用。你知道吗非常感谢您的帮助!你知道吗
您要查找的数据位于
script
元素下。你知道吗您所需要做的就是加载作为脚本主体返回的JSON并遍历dict
输出
https://pastebin.com/kGhMQt61
相关问题 更多 >
编程相关推荐