HtmlAgility并了解节点 [英] HtmlAgility and understand the nodes

查看:60
本文介绍了HtmlAgility并了解节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



这就是我正在处理的关于节点路径并试图破译需要完成的工作的内容。底部路径是我使用Chrome获得的,因为您可以在每个/ li [?]之后看到数字不同。即使li值发生变化,我怎样才能得到product_list下的所有值?



此外,如果每个节点下列出多个值并且我想得到它们怎么办?所有即。



部分#,

价格,

描述

location





 <   h3  >  
< a href = http://www.somesite.com/shop.html title = 产品的一些描述 < span class =code-keyword>> 产品说明< / a < span class =code-keyword>>
< / h3 &g t;


// * [@ id =product_list] / li [1] / div [2] / h3 / a
// * [@ id =product_list] / li [2] / div [2] / h3 / a
// * [@ id =product_list] / li [3] / div [2] / h3 / a
// * [@ id =product_list] / li [4] / div [2] / h3 / a
// * [@ id =product_list] / li [5] / div [2] / h3 / a







感谢任何帮助....

解决方案

尝试删除 li 后的数字:

  //   * [@ id =product_list] / li / div [2] / h3 / a  



方括号中的数字表示您要选择指定索引处的匹配元素。通过删除该限制,您将选择所有匹配的元素。



选择器是 XPath [ ^ ]表达


Hello everyone,

This is what I am dealing with regarding the path to the nodes and trying to decipher what needs to be done. The bottom paths is what I got from using Chrome, as you can see after every /li[?] the number is different. How can I get all the values under the product_list even thought the li value changes?

Also, what if multiple values are listed under each node and I want to get them all ie.

part#,
price,
description
location


<h3>
<a href="http://www.somesite.com/shop.html" title="Some description of the product">Product description</a>
</h3>


//*[@id="product_list"]/li[1]/div[2]/h3/a
//*[@id="product_list"]/li[2]/div[2]/h3/a
//*[@id="product_list"]/li[3]/div[2]/h3/a
//*[@id="product_list"]/li[4]/div[2]/h3/a
//*[@id="product_list"]/li[5]/div[2]/h3/a




Appreciate any help....

解决方案

Try removing the numbers after the li:

//*[@id="product_list"]/li/div[2]/h3/a


The number in square brackets indicates that you want to select the matching element at the specified index. By removing that restriction, you will select all matching elements.

The selector is an XPath[^] expression.


这篇关于HtmlAgility并了解节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆