简体   繁体   English

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

[英]Extract a proper content from the url using jsoup

I'm looking how I can extract the content of news articles like CNN or NewYork times using Jsoup . 我正在寻找如何使用Jsoup提取CNN或NewYork时报等新闻文章的内容。

In fact I had tried the following code: 实际上,我尝试了以下代码:

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

I had received this error: 我收到此错误:

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

Have you an idea please How I can extract a proper text from articles. 请问您有什么主意,我该如何从文章中提取适当的文字。

select调用之后,您的document.select("div.cnn_strycntntlft") contents Element为空-您指定的选择器在从CNN下载的文档中不返回任何匹配项-尝试执行诸如document.select("div.cnn_strycntntlft") ,该操作返回故事div的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM