0

我正在使用 gui-less 浏览器 htmlunits 来检索网页的网页内容,并且该代码在“ http://www.xyzzzzzzz.com.sg/ ”之外的其他网站上运行良好。谁能解释为什么会这样????我已经为所有三个浏览器 CHROME、FIREFOX 和 IE 使用了 HtmlUnit webdriver 作为 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
    }
}
4

1 回答 1

0

驾驶室,请您描述未显示正确的联系是什么意思。因为我不认为代码中有一些错误。有时 JS 会给 HtmlUnit 执行带来问题,所以也可以通过停止它来检查。

于 2014-01-06T18:32:41.157 回答