[英]jSoup get title from img tag
我有一種情況,我需要從img標簽中拉出標題,如下所示。
<img alt="Bear" border="0" src="/images/teddy/5433.gif" title="Bear"/>
我能夠獲取圖片網址。 但是我如何從img標簽獲得標題。 從上面的標題=“ bear”。 我要提取這個。
使用Element#attr()
提取任意元素屬性。
Element img = selectItSomehow();
String title = img.attr("title");
// ...
String html = "<img alt='Bear' border='0' src='/images/teddy/5433.gif' title='Bear'/>";
Document doc = Jsoup.parse(html);
Element e = doc.select("img[title]").first();
String title = e.attr("title");
System.out.println(title);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.