【问题标题】:How to retrieve all the user comments from a site?如何从网站检索所有用户评论?
【发布时间】:2015-03-05 07:22:05
【问题描述】:

我想要这个站点的所有用户 cmets:http://www.consumercomplaints.in/?search=chevrolet

问题是 cmets 只是部分显示,要查看完整的评论我必须点击它上面的标题,并且必须对所有 cmets 重复此过程。

另一个问题是cmets的页面很多。

所以我想将所有完整的 cmets 存储在上述指定站点的 excel 表中。 这可能吗 ? 我正在考虑将 crawler4j 和 jericho 与 Eclipse 一起使用。

我的 visitPage 方法代码: @覆盖 公共无效访问(页面页面){
字符串 url = page.getWebURL().getURL(); System.out.println("网址:" + url);

           if (page.getParseData() instanceof HtmlParseData) {
                   HtmlParseData htmlParseData = (HtmlParseData) page.getParseData();

                   String html = htmlParseData.getHtml();

  //               Set<WebURL> links = htmlParseData.getOutgoingUrls();
  //               String text = htmlParseData.getText();

                   try
                   {
                       String CrawlerOutputPath = "/DA Project/HTML Source/";
                       File outputfile = new File(CrawlerOutputPath);

                       //If file doesnt exists, then create it
                        if(!outputfile.exists()){
                            outputfile.createNewFile();
                        }

                       FileWriter fw = new FileWriter(outputfile,true);  //true = append file
                       BufferedWriter bufferWritter = new BufferedWriter(fw);
                       bufferWritter.write(html);
                       bufferWritter.close();
                       fw.write(html);
                       fw.close();

                   }catch(IOException e)
                   {
                       System.out.println("IOException : " + e.getMessage() );
                       e.printStackTrace();
                   }

                   System.out.println("Html length: " + html.length());
           }
   }

提前致谢。任何帮助将不胜感激。

【问题讨论】:

    标签: java comments excel-2013 crawler4j jericho-html-parser


    【解决方案1】:

    是的,这是可能的。

    • 开始在您的搜索网站上抓取 (http://www.consumercomplaints.in/?search=chevrolet)
    • 使用 crawler4j 的 visitPage 方法只关注 cmets 和正在进行的页面。
    • 从 crawler4j 中获取 html 内容并将其推送到 jericho
    • 过滤出您要存储的内容并将其写入某种 .csv 或 .xls 文件(我更喜欢 .csv)

    希望对你有帮助

    【讨论】:

    • 嗨 Tobias ...谢谢您的回答。但我需要你多一点帮助。能不能帮我写一下 crawler4j 的 visitPage 方法。
    • 我已在问题中附加了我的 visitPage 方法代码。您能否告诉我如何编辑我的代码以从爬取的数据中获取 cmets。谢谢
    • 首先我会使用 shouldVisit 方法来过滤页面。一些正则表达式只跟随“consumercomplaints.in/?search=chevrolet[.......]”和“consumercomplaints.in[......ending with -c + some number] 应该没问题。现在检查 visitPage 是否是带有评论的页面并过滤掉评论。(提示:类是“复杂文本”。)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    相关资源
    最近更新 更多