【问题标题】:HOW to get article content from many urls webpages如何从许多 urls 网页中获取文章内容
【发布时间】:2015-12-15 06:38:42
【问题描述】:

我已经搜索了更多正确的解决方案,但我仍然无法解决。 请看这个并帮助我。

   import java.io.BufferedReader;
   import java.io.BufferedWriter;
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.InputStreamReader;
   import java.io.OutputStreamWriter;
   import java.io.PrintWriter;

   import org.jsoup.Jsoup;
   import org.jsoup.nodes.Document;
   import org.jsoup.nodes.Element;
   import org.jsoup.select.Elements;

   public class NewClass {


   public static void main(String[] args) throws IOException {


   Document doc = Jsoup.connect("http://tamilblog.ishafoundation.org").get();
         Elements section = doc.select("section#content");
  Elements article = section.select("article");
  for (Element a : article) {
    System.out.println("Title : \n" + a.select("a").text());
    System.out.println("Article summary: \n" + a.select("div.entry-summary").text());

  }

  }
}

我有上述代码用于从单个页面获取文章及其内容。

   Document doc = Jsoup.connect("http://tamilblog.ishafoundation.org").get();

我想为几个网站这样做。

在这一行或使用一些迭代,我想将我的代码应用于多个网页,比如 500+。 我想将它保存在其文章标题及其内容下的单独文本文档中。

我是编码新手,所以我找不到正确的代码。

过去两个月我一直在编写这段代码来创建我的代码。

【问题讨论】:

    标签: java html url web-scraping jsoup


    【解决方案1】:

    对于初学者,你可以这样做,

    String[] urls={"http://tamilblog.ishafoundation.org","url2","url3"};//your 500 urls wil be stored here, 
    
        for(String url: urls){
            Document doc = Jsoup.connect(url).get();
            Elements section = doc.select("section#content");
            Elements article = section.select("article");
            for (Element a : article) {
                System.out.println("Title : \n" + a.select("a").text());
                System.out.println("Article summary: \n" + a.select("div.entry-summary").text());
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 2011-01-23
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      相关资源
      最近更新 更多