xml XPath 通过 id 属性获取另一个属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6844585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XPath to get another attribute by id attribute
提问by user151841
I am using XPath to pull data off of a web page.
我正在使用 XPath 从网页中提取数据。
I have a link that I want to get the href value of. I can reference it through its unique id: id('unique-id'), but that gives me the string between the <a>tags.
我有一个想要获取其 href 值的链接。我可以通过它的唯一 id: 来引用它id('unique-id'),但这给了我<a>标签之间的字符串。
How do I get the value of the hrefattribute?
如何获取href属性的值?
回答by Kirill Polishchuk
Try this XPath: //a[@id = 'unique-id']/@href. This XPath will select hrefattribute of aelement with attribute id= unique-id
试试这个XPath: //a[@id = 'unique-id']/@href。此 XPath 将选择具有属性=href的a元素的属性idunique-id

