无法如预期使用requests_htm提取结果

2024-04-27 15:49:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法使用requests\u html提取正确的结果:

>>> from requests_html import HTMLSession
>>> session = HTMLSession()
>>> r = session.get('https://www.amazon.com/dp/B07569DYGN')
>>> r.html.find("#productDetails_detailBullets_sections1")
[]

我可以在源内容中找到id'productDetails\udetailBullets_sections1':

^{pr2}$

实际上,这个问题同样存在于PyQuery中。在

为什么requests_html找不到这个元素?在


Tags: fromhttpsimportcomamazongetsessionhtml
1条回答
网友
1楼 · 发布于 2024-04-27 15:49:48

我在搜索#comparison_price_row,它仍然能找到一些东西。源代码中的下一个id是comparison_shipping_info_row,但是搜索#comparison_shipping_info_row会返回一个空数组。这两个元素位于同一级别(同一父级)。我检查了所有的来源,但没有发现两者之间的问题。在

一开始。在

然后我看到在这两者之间有一个NUL字节,这可能会使库出错。在

从输入中删除NUL字节后,可以找到想要的元素:

r2 = requests_html.HTML(html=r.text.replace('\0', ''))
r2.find('#productDetails_detailBullets_sections1')

[<Element 'table' role='presentation' class=('a-keyvalue', 'prodDetTable') id='productDetails_detailBullets_sections1'>]

相关问题 更多 >