本文介绍了jSoup从img标签获取标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一种情况,需要从如下所示的img标签中提取标题.
I have a scenario where I need to pull the title from a img tag like below.
<img alt="Bear" border="0" src="/images/teddy/5433.gif" title="Bear"/>
我能够获取图片网址.但是我如何从img标签获得标题.从上面的标题="bear".我要提取它.
I was able to get the image url. But how do i get the title from the img tag.From above title = "bear". I want to extract this.
推荐答案
使用 Element#attr()
提取任意元素属性.
Use Element#attr()
to extract arbitrary element attributes.
Element img = selectItSomehow();
String title = img.attr("title");
// ...
另请参见:
- Jsoup食谱-从元素中提取属性,文本和HTML
- Jsoup Cookbook - Extract attributes, text, and HTML from elements
See also:
这篇关于jSoup从img标签获取标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!