From: Shaun M. <sma...@gm...> - 2014-12-16 12:43:23
|
Sample URL: http://www.heatpressnation.com/sublimation-printers-ink.html Websocket URL: https://us22.zopim.com When calling that page, HtmlUnit never completes because of the websocket connection to zopim.com. How can I force the page to finish after a set timeout or identify the web socket and close it. Here is the meat of my code: try { URL url = new URL(strUrl); WebRequest webRequest = new WebRequest(url); WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); new WebConnectionWrapper(webClient) { public WebResponse getResponse(WebRequest request) throws IOException { System.err.println("Url: " + request.getUrl()); WebResponse response = super.getResponse(request); if(response.getContentType().equals("text/html") || response.getContentType().equals(null) || response.getContentType().equals("") || response.getContentType().equals("application/x-www-form-urlencoded")) { System.out.println(response.getWebRequest().getUrl()); } return response; } }; webClient.getOptions().setTimeout(10000); webClient.setJavaScriptTimeout(5000); webClient.setRefreshHandler(new ImmediateRefreshHandler()); webClient.getPage(webRequest); webClient.waitForBackgroundJavaScript(3000); } catch(Exception error) { System.err.println("Error: " + error.toString()); } |