0

在将此代码用于其他站点时,我得到了正确的 htmlContent,但是一个站点无法正常工作(见下文)。请告知我还能做什么?

public class Test3 {
        public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
            String url = "https : / / altera . wd1 . myworkdayjobs . com / Altera / jobs";
            String content = HtmlPageFetcher.fetchPage(url, "firefox", 50000);
            System.out.println(content);
    }

    public static String fetchPage(String url, String browser, long delayinmillis) {
        WebClient webClient;
        webClient = new WebClient(BrowserVersion.FIREFOX_17);
        webClient.getOptions().setCssEnabled(false);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
        webClient.getOptions().setUseInsecureSSL(true);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());

        String content="";
        try {               
            HtmlPage page = webClient.getPage(url);
            webClient.waitForBackgroundJavaScript(delayinmillis);
            content = page.asXml();
            webClient.closeAllWindows();
            webClient = null;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(webClient!=null)
                webClient.closeAllWindows();
        }
        return content;
    }

我也尝试过 Chrome 和 IE。网页上的数据是由 JSON 填充的(正如我通过 chrome 中的检查元素看到的)

4

1 回答 1

0

做了一个小修复。

请从 Maven 或构建服务器获取最新快照。

于 2015-04-24T09:25:41.547 回答