2016-08-30 33 views
-1

altの属性をjsoupライブラリで読む必要がありますか? 例:jsoupを使ってリンク内のイメージ "alt"属性を読み取る方法は?

<a href="www.test.com"> 
    <img src="http://test.org/images/icon/socialNetwork/telegram-icon.png" border="0" alt="telegram"/> 
</a> 

どのように読むことができますか?ここで

+0

私が間違って引用符も、代わりに '

+1

参照:http://stackoverflow.com/questions/18634215/jsoup-find-all-images-in-html-file -with-alt属性 – willome

答えて

0

は、画像タグのすべてaltの属性を読み込み、コードスニペット、次のとおりです。

String html = "<a href=\"www.test.com\"> <img src=\"http://test.org/images/icon/socialNetwork/telegram-icon.png\" border=\"0\" alt=\"telegram\"></img>"; 
Document document = Jsoup.parse(html); 
Elements elements = document.getElementsByTag("img"); 
for (Element e : elements) { 
    String alt = e.attr("alt"); 
    System.out.println("alt: " + alt); 
} 
関連する問題