HTMLAgilityPack xpath
我遇到了这个问题,请问有人可以帮助我吗?
从下面的 URL,我希望获取
<a href="/borsa/azioni/scheda.html?isin=IT0001233417&lang=en">A2A</a>
我正在使用的 XPath
语法的内部文本,但不返回任何数据:
.//table[@class='table_dati']//tbody[@class='constituents']//tr//td[@class='name']//a
URL 是 http://www.borsaitaliana.it /borsa/azioni/ftse-mib/lista.html?lang=en&page=1
预先感谢,
格兰特
I have hit a wall with this one, please could someone help me out?
From the URL below I am looking to get to the inner text of
<a href="/borsa/azioni/scheda.html?isin=IT0001233417&lang=en">A2A</a>
The XPath
syntax I am using doesn't return any data:
.//table[@class='table_dati']//tbody[@class='constituents']//tr//td[@class='name']//a
The URL is
http://www.borsaitaliana.it/borsa/azioni/ftse-mib/lista.html?lang=en&page=1
Thanks in advance,
Grant
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
//tbody[@class='constituents']//td[@class='name']/a
怎么样?实际上,这应该工作得很好。How about
//tbody[@class='constituents']//td[@class='name']/a
? This should work pretty well, actually.您的 XPath 以
.
开头,因此它是相对于上下文节点的。但你没有告诉我们任何有关背景的信息。也许您想省略最初的.
并使其成为“绝对”:无论您在哪里查找,我也会将
//
更改为/
对于直系子女(一般不是后裔)关系。Your XPath starts with
.
, so it is relative to the context node. But you haven't told us anything about the context. Maybe you want to omit the initial.
and make it "absolute":I would also change the
//
to/
wherever you're looking for a direct child (not descendant in general) relationship.根据我的经验,HTMLAgilityPack 与 tbody 标签配合得不好。我只是用 tr td 跟踪表格来找到正确的单元格,完全跳过 tbody 。
From my experience, HTMLAgilityPack doesn't play nice with the tbody tag. I just follow up the table with the tr td to find the right cell, skipping tbody altogether.