[英]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.