Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要获取标签属性href的值。 我知道使用我可以获得 href 属性值。aa.attr("href")
href
a
a.attr("href")
但我想知道是否有任何其他方法可以获取Jsouphref中的属性jTidy (使用类似的语法//a/@href)。
jTidy
//a/@href
意味着我可以使用一些选择器语法直接获取属性吗?
谢谢。
不,您不能通过单个选择器检索属性值。其目的是根据各种标准选择元素。
但是您只能选择那些具有该属性的元素,然后询问它的值。
Element withAttr = doc.select("a[href]").first(); String attrAvlue = withAttr.attr("href");