0

我正在尝试编写一个显示最后一个“你知道吗?”的小 android 程序(不要介意混乱)。来自维基百科。但由于某种原因,Jsoup 没有找到它。

问题是什么?


部分代码:

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();
    }
}

部分维基百科源代码:

<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

4

1 回答 1

1

您的代码在桌面上运行良好。根据互联网访问权限检查您的 android 设置。检查真正的问题在哪里也是一个好主意。

一些提示:

  • e.printStackTrace();用记录器替换
  • message也将变量的值写入记录器
  • 你在使用AsyncTask吗?
  • 是否有任何错误、异常或类似情况?
于 2013-05-15T18:42:07.333 回答