【问题标题】:How to perform web scraping to find specific linked pages in Java on Google App Engine?如何在 Google App Engine 上执行网页抓取以查找 Java 中的特定链接页面?
【发布时间】:2011-04-26 13:26:37
【问题描述】:

我需要从不提供 RSS 提要的远程网站检索文本。

我所知道的是,我需要的数据始终位于从主页 (http://www.example.com/) 链接到的页面上,其中的链接包含文本“Invoices Report”。

例如:

<a href="http://www.example.com/data/invoices/2010/10/invoices-report---tuesday-october-12.html">Invoices Report - Tuesday, October 12</a>

因此,我需要在主页上找到与此模式匹配的所有链接,然后从位于名为<div class="invoice-body"> 的标记内的那些页面中检索所有文本。

是否有 Java 工具可以帮助解决此问题?是否有任何专门针对 Google App Engine for Java 的工具可用于执行此操作?

【问题讨论】:

    标签: java regex google-app-engine screen-scraping web-scraping


    【解决方案1】:

    查看http://code.google.com/appengine/docs/java/urlfetch/overview.html

    您可以使用 UrlFetch 服务逐行读取 www.example.com/index.html,并使用正则表达式查找“​​发票报告”。

    URL url = new URL("http://www.example.com/index.html");
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;
    
    while ((line = reader.readLine()) != null) {
        checkLineForTextAndAddLinkOrWhatever(line);
    }
    reader.close();
    

    如果链接可能在多行上,您可能需要不同类型的阅读器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多