如何webscrape scholar.google.com在Java中?
-
20-09-2019 - |
题
我想写一个Java FUNC grabTopResults(String f)
这样grabTopResults("automata theory")
返回我的前100引上scholar.google.com论文为“自动机理论”的清单。
有没有人有什么库将让我的生活更轻松的建议?
谢谢!
解决方案
正如我敢肯定,谷歌可以承受的带宽,我会忽略这是否是不道德的/非法/谷歌的条款及条件禁止
问题 你需要做的第一件事情就是搞清楚HTTP请求(或请求),你需要为了与你所需要的数据,以获得页面的问题。一旦你想通了这一点,使用 HttpClient的发出相同从Java代码请求。以前的链接显示了示例代码,解释了如何做到这一点。
一旦你下载了相关页面的内容,你需要使用一个HTML解析器来提取您感兴趣的数据,的 通过peperg建议杰里科解析器是一个很好的选择。
如果谷歌的警察来敲门,你从来没有听说过我,好不好?
其他提示
我使用 http://jericho.htmlparser.net/docs/index.html一>。谷歌学术没有API(的http:// code.google.com/p/google-ajax-apis/issues/detail?id=109 )。当然它不是由谷歌允许的(读使用规则。自动requestr被禁止)。
下面是一个比特的示例代码使用开源产品 TestPlan中。它是一个独立的产品,但如果你真的需要它,我可以帮你将它纳入你的Java代码(它是用Java编写本身)。
GotoURL http://scholar.google.com/
SubmitForm with
%Params:q% automate theory
end
set %Items% as response //div[@class='gs_r']
foreach %Item% in %Items%
set %Title% as selectIn %Item% h3
Notice %Title%
end
此产生输出像下面(我的IP是德国,因此德国响应)。很显然,只要你喜欢,你可以格式化,或将其写入文件;这仅仅是一个粗略的测试。
00000000-00 GOTOURL http://scholar.google.com/
00000001-00 SUBMITFORM default
00000002-00 NOTICE [ZITATION] Stochastic complexity in statistical inquiry theory
00000003-00 NOTICE AUTOMATED THEORY FORMATION IN MATHEMATICS1
00000004-00 NOTICE Constraint generation via automated theory formation
00000005-00 NOTICE [BUCH] Automated theorem proving: after 25 years
00000006-00 NOTICE [BUCH] Introduction to the Theory of Computation
00000007-00 NOTICE [ZITATION] Computer-controlled systems: theory and design
00000008-00 NOTICE [BUCH] … , randomness & incompleteness: papers on algorithmic information theory
00000009-00 NOTICE [BUCH] Automatic control systems
00000010-00 NOTICE [BUCH] VLSI physical design automation: theory and practice
00000011-00 NOTICE Singular Control Systems.
不隶属于 StackOverflow