我不知道为什么以下查询不起作用:
//a/@href[@class='specified_string']
Run Code Online (Sandbox Code Playgroud)
ndi*_*dim 48
反过来试试:
//a[@class='specified_string']/@href
Run Code Online (Sandbox Code Playgroud)
毕竟,class是<a>元素的属性,而不是属性的href属性.
属性不能包含属性.只有元素才能拥有属性.
原始的XPath表达式:
//a/@href[@class='specified_string']
Run Code Online (Sandbox Code Playgroud)
选择任何元素的任何href属性a,以使该href属性具有class值为的属性'specified_string'.
你想要的是:
//a[@class='specified_string']/@href
Run Code Online (Sandbox Code Playgroud)
即:具有值的href属性的任何a元素的属性.class'specified_string'