Java 使用jsoup从url中提取适当的内容

Java 使用jsoup从url中提取适当的内容,java,jsoup,Java,Jsoup,我正在研究如何使用Jsoup提取CNN或《纽约时报》等新闻文章的内容 事实上,我已经尝试了以下代码: Document document = Jsoup.connect("http://edition.cnn.com/2013/11/10/world/asia/philippines-typhoon-haiyan/index.html").get(); Element contents = document.select("#content").first(); System.out.pri

我正在研究如何使用
Jsoup
提取CNN或《纽约时报》等新闻文章的内容

事实上,我已经尝试了以下代码:

Document document = Jsoup.connect("http://edition.cnn.com/2013/11/10/world/asia/philippines-typhoon-haiyan/index.html").get();

Element contents = document.select("#content").first();

System.out.println(contents.html()); 

System.out.println(contents.text()); 
我收到了这个错误:

Exception in thread "main" java.lang.NullPointerException
at com.clearforest.Test.main(Test.java:36)

您知道如何从文章中提取正确的文本吗。

在调用
select
后,您的
contents元素
为空-您指定的选择器在从CNN下载的文档中未返回匹配项-尝试类似
document.select(“div.CNN\u strycntlft”)的操作
返回故事div内容

您没有提供有关问题所在的足够信息。异常信息清楚地表明在我们班的第36行有一个NPE。也许你可以看看或者把它贴在这里?