DennisVDB
DennisVDB

Reputation: 1357

Jsoup doesnt find the specified element

I'm trying to write a little android program (don't mind the messiness) that shows the last "Did you know?" from Wikipedia. But for some reason Jsoup doesn't find it.

What is the problem?


Part of the code:

Document document = null;
try {
    document = Jsoup.connect("https://en.wikipedia.org/wiki/Portal:Mathematics/Did_you_know/1").get();
} catch (IOException e) {
    e.printStackTrace();
}
//Document document = Jsoup.parse("test.html");
if (document != null) {
    Element element = document.select("div#mw-content-text").first();
    if (element == null) {
        message = "empty";
    } else {
        message = element.html();
    }
}

Part of the wikipedia source code:

<div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><p>...that outstanding mathematician <a href="/wiki/Grigori_Perelman" title="Grigori Perelman">Grigori Perelman</a> was offered a <a href="/wiki/Fields_Medal" title="Fields Medal">Fields Medal</a> in 2006, in part for his proof of the <a href="/wiki/Poincar%C3%A9_conjecture" title="Poincaré conjecture">Poincaré conjecture</a>, which he declined?</p>

https://en.wikipedia.org/wiki/Portal:Mathematics/Did_you_know/1

Upvotes: 0

Views: 126

Answers (1)

ollo
ollo

Reputation: 25350

Your code works fine on a desktop. Check your android settings according to internet access rights. Also it's a good idea to check where's the real problem.

Some hints:

  • replace e.printStackTrace(); with a logger
  • write the value of message variable to a logger too
  • are you using an AsyncTask?
  • Are there any errors, exception or something similar?

Upvotes: 1

Related Questions