以下代码无法呈现Google地图:
String completeUrl = "https://www.google.com.ph/maps/search/wallmart";
System.out.println(completeUrl);
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52);
webClient.waitForBackgroundJavaScript(20000);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.setAjaxController(new AjaxController(){
@Override
public boolean processSynchron(HtmlPage page, WebRequest request, boolean async) {
return true;
}
});
//webClient.getOptions().setTimeout(20000);
HtmlPage page = webClient.getPage(completeUrl);
我们得到的是带有此代码片段的HTML:
<a class="no-script-help-link" href="//support.google.com/maps/?hl=en&authuser=0&p=no_javascript" target="_blank"> Enable JavaScript to see Google Maps. </a>
此代码有什么问题?因为 20秒已经等待Javascript了。
答案 0 :(得分:1)
很多事情:
已完成本地测试并在日志中遇到一些js错误。如果您希望修复此错误,请尝试隔离最小情况(http://htmlunit.sourceforge.net/submittingJSBugs.html)并向HtmlUnit错误跟踪器报告。