Mark Korzhov
Mark Korzhov

Reputation: 2159

How to parse 'div' without name?

Using Jsoup:

Element movie_div = doc.select("div.movie").first();

I got a such HTML-code:

<div class="movie"> 
    <div> 
        <div>
            <strong>Year:</strong> 2014
        </div> 
        <div>
            <strong>Country:</strong> USA
        </div> 
    </div> 
</div>

How can I use jsoup to extract the country and the year?

For the example html I want the extracted values to be "2014" and "USA".

Thanks.

Upvotes: 1

Views: 140

Answers (2)

fabian
fabian

Reputation: 82491

Use

Element e = doc.select("div.movie").first().child(0);
List<TextNode> textNodes = e.child(0).textNodes();
String year = textNodes.get(textNodes.size()-1).text().trim();
textNodes = e.child(1).textNodes();
String country = textNodes.get(textNodes.size()-1).text().trim();

Upvotes: 2

Fractaliste
Fractaliste

Reputation: 5957

Did you try something like:

Element movie_div = doc.select("div.movie strong").first();

And to get the text value you should try;

movie_div.text();

Upvotes: 0

Related Questions