问题
Help solve the problem, it is necessary to pull some data from Wikipedia, I'll show them in the picture below:
In the page code, these data are here:
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:
回答1:
Get the parent
divby its ID (which should be unique):Elements parent = doc.select("div#mw-body-content");Get all
ptags in this element (including the second one you would like to have):Elements paragraphs = parent.getElementsByTag("p");Take the second of it:
String text = paragraphs.get(1).text();
来源:https://stackoverflow.com/questions/23978520/jsoup-find-element