1

我正在尝试使用 jSoup从这个 url http://skyalipi.blogspot.com/2011/04/there-is-no-resistance-without.html解析 html。我正在使用此代码

Document doc = Jsoup.parse("http://skyalipi.blogspot.com/2011/04/there-is-no-resistance-without.html");  

       Log.d("test", "the elements"+doc);

在日志中,我得到以下信息

05-26 12:05:05.355: DEBUG/test(696): the elements<html>
05-26 12:05:05.355: DEBUG/test(696):  <head></head>
05-26 12:05:05.355: DEBUG/test(696):  <body>
05-26 12:05:05.355: DEBUG/test(696):   http://skyalipi.blogspot.com/2011/04/there-is-no-resistance-without.html 
05-26 12:05:05.355: DEBUG/test(696):  </body>
05-26 12:05:05.355: DEBUG/test(696): </html>

我想获取段落内容。我不知道我哪里出错了。我也参考了以下网址http://jsoup.org/cookbook/extracting-data/attributes-text-html请帮忙

4

1 回答 1

1

Jsoup 将您的 URL 视为您要解析的文本,并将其转换为有效的 HTML 以便可以对其进行解析。我认为您想连接到该站点并检索该 url 的内容,然后解析结果:

Document doc = Jsoup.connect("http://skyalipi.blogspot.com/2011/04/there-is-no-resistance-without.html").get();

编辑

查看文档以获取示例。您可以执行以下操作:

Element example = doc.getElementById("alternatives1");
Log.d("test","example "+example.text());
于 2011-05-26T07:11:39.303 回答