我尝试修改代码crawler4j-Quickstart example
我想抓取以下链接
https://www.google.com/search?biw=1366&bih=645&tbm=nws&q=%22obama%22&oq=%22obama%22&gs_l=serp.3..0l5.825041.826084.0.826833.5.5.0.0.0.0.187.572.2j3.5.0....0...1c.1.64.serp..0.3.333...0i13k1.Tmd9nARKIrU
这是一个包含关键字 obama
的Google新闻搜索链接我尝试修改mycrawler.java
@Override
public boolean shouldVisit(Page referringPage, WebURL url) {
String href = url.getURL().toLowerCase();
return !FILTERS.matcher(href).matches()
&& href.startsWith("https://www.google.com/search?biw=1366&bih=645&tbm=nws&q=%22obama%22&oq=%22obama%22&gs_l=serp.3..0l5.825041.826084.0.826833.5.5.0.0.0.0.187.572.2j3.5.0....0...1c.1.64.serp..0.3.333...0i13k1.Tmd9nARKIrU/");
}
另外,controller.java
/*
* For each crawl, you need to add some seed urls. These are the first
* URLs that are fetched and then the crawler starts following links
* which are found in these pages
*/
//controller.addSeed("http://www.ics.uci.edu/~lopes/");
// controller.addSeed("http://www.ics.uci.edu/~welling/");
controller.addSeed("https://www.google.com/search?biw=1366&bih=645&tbm=nws&q=%22obama%22&oq=%22obama%22&gs_l=serp.3..0l5.825041.826084.0.826833.5.5.0.0.0.0.187.572.2j3.5.0....0...1c.1.64.serp..0.3.333...0i13k1.Tmd9nARKIrU");
/*
* Start the crawl. This is a blocking operation, meaning that your code
* will reach the line after this only when crawling is finished.
*/
controller.start(MyCrawler.class, numberOfCrawlers);
然后,它显示错误
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
BUILD SUCCESSFUL (total time: 43 seconds)
我的代码修改错了吗?
我尝试使用谷歌搜索链接以外的其他网址。它有效。 我猜它不能抓取谷歌搜索链接。任何想法解决它?
答案 0 :(得分:2)
您收到的错误与您的代码修改无关。 相反,它与错误的配置和丢失的罐子有关。
SLF4J绑定是SLF4J执行日志记录所必需的,否则它将使用您在错误消息中看到的NOP记录器实现。
要解决此问题,请将SLF4J绑定jar文件添加到项目中,例如slf4j-simple-<version>.jar
您可以参考SLF4J Manual获取更详细的解释。
<强>更新强>
我认为您不允许基于Google's robots.txt抓取谷歌搜索结果,该搜索结果禁止其网站使用后缀/search
进行抓取,也允许抓取TOS。 / p>
请勿滥用我们的服务。例如,不要干涉我们的 服务或尝试使用接口以外的方法访问它们 以及我们提供的说明。您只能将我们的服务用作 法律允许,包括适用的出口和再出口管制 法律法规。我们可能会暂停或停止向我们提供服务 如果您不遵守我们的条款或政策,或者如果您遵守我们的条款或政策 调查可疑的不当行为。
您可以考虑使用Google's Custom Search API来符合其服务条款。