HtmlUnit 获取页面错误
HtmlUnit gets page error
我正在尝试解析此页面。
http://www.reuters.com/article/2015/07/08/us-china-cybersecurity-idUSKCN0PI09020150708
我的代码如下所示
WebClient webClient = new WebClient(BrowserVersion.CHROME);
final HtmlPage page = webClient.getPage("http://www.reuters.com/article/2015/07/08/us-alibaba-singapore-post-idUSKCN0PI03J20150708");
System.out.println(page.asXml());
它给了我很多警告和巨大的调用堆栈。主要与 javascript 引擎有关。
我已经使用了这些选项
webClient.waitForBackgroundJavaScript(1000000);
webClient.setJavaScriptTimeout(1000000);
但似乎没有任何效果。该页面执行javascript加载页面内容。我需要等待页面加载才能获取内容。有什么办法可以解决这个问题吗?
刚拿到页面需要wait
,也有"addImpression" is not defined
的错误,不知道是在哪个JavaScript定义的[=14] =]
我感觉你用的不是最新版本,因为没有很多警告。
使用 latest snapshot 我通过以下方式获取内容:
try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
final HtmlPage page = webClient.getPage("http://www.reuters.com/article/2015/07/08/us-alibaba-singapore-post-idUSKCN0PI03J20150708");
webClient.waitForBackgroundJavaScript(10000);
System.out.println(page.asText());
}
我正在尝试解析此页面。
http://www.reuters.com/article/2015/07/08/us-china-cybersecurity-idUSKCN0PI09020150708
我的代码如下所示
WebClient webClient = new WebClient(BrowserVersion.CHROME);
final HtmlPage page = webClient.getPage("http://www.reuters.com/article/2015/07/08/us-alibaba-singapore-post-idUSKCN0PI03J20150708");
System.out.println(page.asXml());
它给了我很多警告和巨大的调用堆栈。主要与 javascript 引擎有关。 我已经使用了这些选项
webClient.waitForBackgroundJavaScript(1000000);
webClient.setJavaScriptTimeout(1000000);
但似乎没有任何效果。该页面执行javascript加载页面内容。我需要等待页面加载才能获取内容。有什么办法可以解决这个问题吗?
刚拿到页面需要wait
,也有"addImpression" is not defined
的错误,不知道是在哪个JavaScript定义的[=14] =]
我感觉你用的不是最新版本,因为没有很多警告。
使用 latest snapshot 我通过以下方式获取内容:
try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
final HtmlPage page = webClient.getPage("http://www.reuters.com/article/2015/07/08/us-alibaba-singapore-post-idUSKCN0PI03J20150708");
webClient.waitForBackgroundJavaScript(10000);
System.out.println(page.asText());
}