无法通过htmlunit下载webcontent以获取其他网址的特定网址

时间:2014-01-06 02:32:15

标签: java htmlunit htmlunit-driver

我正在使用gui-less浏览器htmlunits来检索网页的webcontent,并且代码适用于除“http://www.xyzzzzzzz.com.sg/”之外的其他网站。任何人都能解释为什么会这样吗????我已经将HtmlUnit webdriver用于所有三个浏览器CHROME,FIREFOX和IE作为BrowserVersion,没有任何工作。

public class Test{

    public static void main(String[] args) throws Exception {

        String url = "http://www.xyzzzzzzz.com.sg/";

        WebClient webClient = new WebClient(BrowserVersion.CHROME);
        webClient.getOptions().setCssEnabled(false);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getCookieManager().setCookiesEnabled(true);
        webClient.getOptions().setUseInsecureSSL(true);

        HtmlPage currentPage = (HtmlPage) webClient.getPage(url);
        String content = currentPage.asXml();
        webClient.waitForBackgroundJavaScript(20000);

        System.out.println(content); // NOT SHOWING PROPER CONTECT
    }
}

1 个答案:

答案 0 :(得分:0)

驾驶你请说明你的意思是什么,不显示正确的CONTECT.Because因为我认为代码中有一些错误。 有时候JS会对HtmlUnit执行问题,所以也可以通过停止来检查。