Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling a JavaScript function with HTMLUnit

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.

like image 533
Der Fede Avatar asked Jan 09 '14 15:01

Der Fede


1 Answers

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

like image 121
Kick Avatar answered Sep 21 '22 02:09

Kick