sách gpt4 ăn đã đi

python - 无法使用 lxml Xpath 解析器解析 html

In lại 作者:太空狗 更新时间:2023-10-30 00:57:06 25 4
mua khóa gpt4 giày nike

我正在尝试解析此页面的评论:http://www.amazon.co.uk/product-reviews/B00143ZBHY

使用以下方法:

mã số

html # a variable which contains exact html as given at the above page.
from lxml import etree
tree = etree.HTML(html)
r = tree.xpath(".//*[@id='productReviews']/tbody/tr/td[1]/div[9]/text()[4]")
print len(r)
print r[0].tag

đầu ra

0
Theo dõi (cuộc gọi gần đây nhất là cuộc gọi cuối cùng):
File "c.py", line 37, in
print r[0].tag
IndexError: list index out of range

p,s,: 当在 firefox 的 xpath 检查器插件上使用相同的 xpath 时,我可以很容易地做到这一点。但是这里没有结果,请帮助!

câu trả lời hay nhất

尝试删除 /tbody形式 XPath — 没有 hiện hữu#productReviews .

import urllib2
html = urllib2.urlopen("http://www.amazon.co.uk/product-reviews/B00143ZBHY").read()
from lxml import etree
tree = etree.HTML(html)
r = tree.xpath(".//*[@id='productReviews']/tr/td[1]/div[9]/text()[4]")
print r[0]

Đầu ra:

bought this as replacement for the original cover which came with my greenhouse and which ripped in the wind. so far this seems a good replacement although for some reason it seems slightly too small for my greenhouse so that i cant zip both sides of the front at the same time. seems sturdier and thicker than the cover i had before so hoping it lasts a bit longer!

关于python - 无法使用 lxml Xpath 解析器解析 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11458902/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress