user3384347
user3384347

Reputation: 31

Jsoup (Find Element)

Help solve the problem, it is necessary to pull some data from Wikipedia, I'll show them in the picture below:

data from wiki

In the page code, these data are here:

code wiki

How to get this data? to do this is by using jsoup.

I tried to do it like this:

 System.out.println(doc.select("div.mw-body-content > p ").first().text());

But the problem is that it so happens that this is not the first

in code, and the second is for something:

desired data

Upvotes: 0

Views: 84

Answers (1)

Thomas Uhrig
Thomas Uhrig

Reputation: 31603

  1. Get the parent div by its ID (which should be unique):

    Elements parent = doc.select("div#mw-body-content");
    
  2. Get all p tags in this element (including the second one you would like to have):

    Elements paragraphs = parent.getElementsByTag("p");
    
  3. Take the second of it:

    String text = paragraphs.get(1).text();
    

Upvotes: 1

Related Questions