Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting attribute value from Div tag through jSoup

I have a Div tag as below

<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? I want to display the value of eventTTL ie:) "4583476000".

like image 852
Geek Avatar asked Feb 10 '12 15:02

Geek


2 Answers

In case if your DIV has no Id:

Element div = doc.select("div[eventTTL]").first();
System.out.println(div.attr("eventTTL"));
like image 139
Victoria Agafonova Avatar answered Sep 18 '22 12:09

Victoria Agafonova


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

like image 44
B. Anderson Avatar answered Sep 20 '22 12:09

B. Anderson