【发布时间】:2012-07-12 14:53:28
【问题描述】:
我正在尝试解析来自此页面的评论:http://www.amazon.co.uk/product-reviews/B00143ZBHY
使用以下方法:
代码
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
输出
0
Traceback (most recent call last):
File "c.py", line 37, in <module>
print r[0].tag
IndexError: list index out of range
p,s,: 在 firefox 的 xpath 检查器插件上使用相同的 xpath 时,我可以轻松地做到这一点。但是这里没有结果,请帮忙!
【问题讨论】:
-
不知道为什么 chrome 在 xpath 中显示 tbody :(