calling a JavaScript function with HTMLUnit

本秂侑毒 提交于 2019-12-23 09:00:02

问题


I'm trying to call the function showPage('3'); of this page, for use the page source code after. I tried to do with htmlUnit like so:

WebClient webClient = new WebClient();

webClient.waitForBackgroundJavaScriptStartingBefore(10000);
HtmlPage page = webClient.getPage("http://www.visittrentino.it/it/cosa_fare/eventi/risultati?minEventDate=09012014&maxEventDate=31012014&tp=searchForm.thismonth&ltp=gennaio");

String javaScriptCode = "showPage('3');";

ScriptResult result = page.executeJavaScript(javaScriptCode);
result.getJavaScriptResult();
System.out.println("result: "+ result);

But it's not working. It prints out:

result: net.sourceforge.htmlunit.corejs.javascript.Undefined@a303147

and other 10000 warnings. What am I doing wrong? I need to change the page of this site for do some crawling on the source code. Is there another way (and maybe more easier) for calling jsp-function from Java code and then navigate in the source of the page? Thank you for any help, have a nice day.


回答1:


You print the ScriptResult object not the content of the page,change the SOP code to result.getNewPage()



来源:https://stackoverflow.com/questions/21024176/calling-a-javascript-function-with-htmlunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!