使用HTMLUnit调用JavaScript函数 [英] calling a JavaScript function with HTMLUnit
问题描述
我正在尝试调用函数 showPage('3');
of 此页面,用于之后的页面源代码。我尝试用 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<p=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:
结果:net.sourceforge.htmlunit.corejs.javascript.Undefined@a303147
result: net.sourceforge.htmlunit.corejs.javascript.Undefined@a303147
和其他10000个警告。我究竟做错了什么?我需要更改此站点的页面以对源代码进行一些爬行。是否有另一种方式(也许更容易)从Java代码调用jsp-function然后在页面源中导航?
感谢您的帮助,祝您度过愉快的一天。
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.
推荐答案
您打印ScriptResult对象而不是内容页面,将SOP代码更改为result.getNewPage()
You print the ScriptResult object not the content of the page,change the SOP code to result.getNewPage()
这篇关于使用HTMLUnit调用JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!