获取 span 标签的标题

huangapple go评论87阅读模式
英文:

Getting title of span tag

问题

我使用getElementsByClass方法获取了一个元素,并注意到了span标签的异常使用。文本并没有跨越一些文本,实际上文本位于标签特性" title "内。

这是我得到的内容:

<span style="background-image: url(/img/colors/q5.png); background-size: contain;" class="c-d-pl c-d" title="stainless steel"></span>

以下是我的代码:

Jsoup.connect("https://www.e-katalog.ru/ek-list.php?search="+product).get().getElementsByClass("c-d").get(0)

有人可以帮助提取span标签的"title"数据吗?

英文:

I fetch an element using getElementsByClass and I noticed unusual use of span tag. Instead of spanning some text, the text is actually inside the tag characteristics - title.

Here is what I get:

&lt;span style=&quot;background-image: url(/img/colors/q5.png); background-size: contain;&quot; class=&quot;c-d-pl c-d&quot; title=&quot;stainless steel&quot;&gt;&lt;/span&gt;

Here is my code:

Jsoup.connect(&quot;https://www.e-katalog.ru/ek-list.php?search_=&quot;+product).get().getElementsByClass(&quot;c-d&quot;).get(0)

Can someone help to fetch the "title" data of the span tag?

答案1

得分: 0

使用attr方法获取标签的属性

尝试以下代码

String s = Jsoup.connect("https://www.e-katalog.ru/ek-list.php?search_=" + product)
                .get()
                .getElementsByClass("c-d")
                .get(0)
                .attr("title");
英文:

Use attr method to get the attributes of tag

Try below code

String s = Jsoup.connect(&quot;https://www.e-katalog.ru/ek-list.php?search_=&quot;+product).get().getElementsByClass(&quot;c-d&quot;).get(0).attr(&quot;title&quot;);

huangapple
  • 本文由 发表于 2020年4月3日 21:21:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/61012870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定