Reputation: 1357
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
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:
e.printStackTrace();
with a loggermessage
variable to a logger tooUpvotes: 1