Retrieving text from a website using JSoup

Im working with JSoup to analyze the html website. I want to get an article (for example) on Wikipedia. I would like to get the text from the main page ( http://en.wikipedia.org/wiki/Main_Page ) from the "From the current article" table.

Here is the code:

Document doc = Jsoup.connect("http://en.wikipedia.org/wiki/Main_Page");
Elements el = doc.select("div.mp-tfa");
System.out.println(el);

The problem is that it does not work properly - it only displays an empty string. The table "From todays featured article" is inserted in the div class = "mp-tfa".

How to get this text in my java program?

Thanks in advance.

+3
source share
2 answers

Edit:

doc.select("div.mp-tfa");

To:

doc.select("div#mp-tfa");

Elements, tag, class Element , :

Document doc = Jsoup.connect("http://en.wikipedia.org/wiki/Main_Page").get();
Elements el = doc.select("div#mp-tfa");
for (Element e : el) {
    System.out.println(e.text());
}

:

The Boulonnais is a heavy draft horse breed from Fr....
+3

, :

Document doc = Jsoup.connect("http://en.wikipedia.org/wiki/Main_Page").get();
Elements el = doc.select("div#mp-tfa");
System.out.println(el);
+1

All Articles