简体   繁体   English

通过 jSoup 从 Div 标签获取属性值

[英]getting attribute value from Div tag through jSoup

I have a Div tag as below我有一个 Div 标签如下

<div id="eventTTL" style="text-transform: uppercase; font-weight: 900;" eventTTL="4583476000">5 days 07:14:41</div>

How do i get the value of eventTTL?我如何获得 eventTTL 的值? I want to display the value of eventTTL ie:) "4583476000".我想显示 eventTTL 的值,即:)“4583476000”。

Element div = doc.getElementById("eventTTL");
String attr = div.attr("eventTTL");
System.out.println(attr);

More info at:https://jsoup.org/cookbook/extracting-data/attributes-text-html更多信息请访问:https ://jsoup.org/cookbook/extracting-data/attributes-text-html

In case if your DIV has no Id:如果您的 DIV 没有 ID:

Element div = doc.select("div[eventTTL]").first();
System.out.println(div.attr("eventTTL"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM