在 google 学者中单击 link using HtmlUnit
Click a link using HtmlUnit in google scholar
我正在使用 HtmlUnit 并尝试在 google scholar 中搜索,然后通过执行以下操作获取 bibtex 项目:
1.go到google学者
2.type我要搜索的文件名。
3.click"cite"link,然后会出现一个小方框
4.in我要按的小方框"import to 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();
我正在使用 HtmlUnit 并尝试在 google scholar 中搜索,然后通过执行以下操作获取 bibtex 项目:
1.go到google学者
2.type我要搜索的文件名。
3.click"cite"link,然后会出现一个小方框
4.in我要按的小方框"import to 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();