我正在使用HtmlUnit并尝试在Google Scholar中搜索,然后通过执行以下操作获得一个bibtex项:
1.转到Google Scholar。
2.输入要搜索的文件名。
3.单击“引用”链接,然后会出现一个小方框。
4.在小方框中,我想按“导入到bibtex”并获取文本。
例如,您可以查看此页面并尝试:https://scholar.google.com/scholar?q=internet+of+things+for+smart+cities&btnG=&hl=en&as_sdt=0%2C5
我可以访问搜索页面,但无法完成其他步骤。
这是我的代码
WebClient webClient = new WebClient(BrowserVersion.CHROME);
HtmlPage page = webClient.getPage("https://scholar.google.com/");
HtmlInput searchBox = page.getElementByName("q");
searchBox.setValueAttribute("internet of things for smart cities");
HtmlButton googleSearchSubmitButton = page.getElementByName("btnG");
page = googleSearchSubmitButton.click();
HtmlAnchor anchor = page.getAnchorByName("Cite");
page = anchor.click();
System.out.println(page.asText());
webClient.close();
有什么帮助吗?
最佳答案
这是您尝试做的事情的开始:
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = webClient.getPage("https://scholar.google.com/");
HtmlInput searchBox = (HtmlInput) page.getElementById("gs_hp_tsi");
searchBox.setValueAttribute("internet of things for smart cities");
HtmlButton googleSearchSubmitButton = page.getElementByName("btnG");
page = googleSearchSubmitButton.click();
HtmlAnchor anchor = page.getAnchorByText("Cite");
anchor.click();
webClient.waitForBackgroundJavaScript(5000);
HtmlAnchor linkBibTex = page.getAnchorByText("BibTeX");
TextPage neededPage = linkBibTex.click();
System.out.println(neededPage.getContent());
webClient.close();