XPath query to select all href attributes of tag, which 'class' attribute equals specified string

后端 未结 4 1119
时光取名叫无心
时光取名叫无心 2020-12-30 00:20

I don\'t know why following query doesn\'t work:

//a/@href[@class=\'specified_string\']
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 00:27

    An attribute cannot have attributes. Only elements can have attributes.

    The original XPath expression:

    //a/@href[@class='specified_string'] 
    

    selects any href attribute of any a element, such that the href attribute has an attribute class whose value is 'specified_string'.

    What you want is:

    //a[@class='specified_string']/@href 
    

    that is: the href attribute of any a element that has class atribute with value 'specified_string'.

提交回复
热议问题