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")
しかし、Jsoupの (のような構文を使用して)のhrefように属性を取得する他の方法があるかどうかを知りたいです。jTidy//a/@href
jTidy
//a/@href
セレクター構文を使用して属性を直接取得できますか?
ありがとう。
いいえ、単一のセレクターで属性値を取得することはできません。その目的は、さまざまな基準によって要素を選択することです。
ただし、属性を持つ要素のみを選択して、その値を尋ねることができます。
Element withAttr = doc.select("a[href]").first(); String attrAvlue = withAttr.attr("href");