'Retrieve time tag with Jsoup

This is my Html:

<div id="trestleLifts">
            <header class="tableHeader">
                <time>as of 4/23/15 @5:18 AM MST</time>
                <h2>Lifts</h2>
            </header>

I need the time Tag, but cant resolve it.

I try with this code, but the app crash

  Document docw = Jsoup.connect(url).get();
  Element doc = docw.getElementById("header.tableHeader");
            Elements h1=doc.getElementsByTag("time");
            String tit = h1.text();


Solution 1:[1]

Element doc = docw.getElementById("header.tableHeader");

doesn't make much sense since there is no tag with id="header.tableHeader" attribute.

Since you are using CSS selector you want select method instead to pick <header class="tableHeader">.

Elements doc = docw.select("header.tableHeader");

Than just pick time element

Elements h1 = doc.select("time");

BTW you can do it all in one call via

Elements h1 = doc.select("header.tableHeader time");

Based on your comment in which you include address of page you want to parse, it seems that problem with this solution is that <time> is empty <time></time> after page is loaded and its content is later generated by JavaScript. In that case Jsoup will not be able to help you, because it is HTML parser without support of JS engine. You will have to use different tool like selenium webdriver or HTMLutils.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1