gpt4 book ai didi

java - 如何执行网络抓取以在 Google App Engine 上查找 Java 中的特定链接页面?

转载 作者:搜寻专家 更新时间:2023-11-01 02:54:42 25 4
gpt4 key购买 nike

我需要从不提供 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 的工具可以用来执行此操作?

最佳答案

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

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

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

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

关于java - 如何执行网络抓取以在 Google App Engine 上查找 Java 中的特定链接页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3952939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com