我正在尝试使用 HTMLUnit 来获取网页(https://www.coursera.org/courses)上的 javascript 元素,它只加载 html 数据。如何让它显示 javascript 容器中显示的信息?
谢谢!
我当前的代码:
public String DownloadPage(String str){
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.getOptions().setTimeout(20000);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
try{
HtmlPage page = webClient.getPage(str);
XmlPage page2 = webClient.getPage(str);
int n = webClient.waitForBackgroundJavaScript(100000);
System.out.println("Executing " + n + " JavaSript jobs!");
System.out.println("OUTPUT: " + page2);
System.out.println("OUTPUT: " + page.asXml());
webClient.closeAllWindows();
}
catch(IOException e){
JOptionPane.showMessageDialog(null, "error");
}
webClient.closeAllWindows();
return "";
}