使用xpath检索具有多个类名的html标记

时间:2015-07-29 06:12:18

标签: c# xpath html-agility-pack

我使用HTMLAgility包提取某些html页面的内容,我使用下面的html代码

span class="custombutton selling_price"

那么如何使用2个类名访问span中的内容 我使用的xpath在这里

//span[@class='custombutton selling_price']

1 个答案:

答案 0 :(得分:0)

我通常建议使用此结构来搜索以空格分隔的属性值:

contains(concat(' ', @attr, ' '), concat(' ', $value, ' '))

这会在值的两端附加一个空格,确保您不会获得部分匹配。

由于CSS类没有特定的顺序,因此搜索其中两个意味着执行以上两次:

//span[
    contains(concat(' ', @class, ' '), ' custombutton ') and
    contains(concat(' ', @class, ' '), ' selling_price ')
]
相关问题