【问题标题】:Dynamic content of Web Page not loaded totally using Htmlunit WebClient网页的动态内容未完全使用 Htmlunit WebClient 加载
【发布时间】:2019-05-22 11:04:57
【问题描述】:

我正在尝试加载网页 (https://genpact.taleo.net/careersection/sgy_external_career_section/jobsearch.ftl?lang=en) 以使用 HtmlUnit WebClient 进行抓取。但内容未正确加载。例如,我找不到应用按钮。 我的网络客户端代码如下

webClient.setCssErrorHandler(new DefaultCssErrorHandler());
        webClient.setJavaScriptErrorListener(new DefaultJavaScriptErrorListener());
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());
        webClient.getCookieManager().setCookiesEnabled(true);
        webClient.waitForBackgroundJavaScript(60000);

有人可以帮我解决这个问题

【问题讨论】:

    标签: javascript java htmlunit


    【解决方案1】:

    这对我有用

    public static void main(String[] args) throws IOException{
        final String url = "https://genpact.taleo.net/careersection/sgy_external_career_section/jobsearch.ftl?lang=en";
    
        try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_60)) {
            HtmlPage page = webClient.getPage(url);
    
            // waitForBackgroundJavaScript has to be called after every action
            // this page is really slow wait for the last part of the dynamic content
            while(!page.asText().contains("Previous\r\n1\r\n2\r\n3\r\n4\r\n")) {
                webClient.waitForBackgroundJavaScript(1_000);
            }
    
            System.out.println("-------------------------------------------------------------------------------");
            System.out.println(page.asText());
            System.out.println("-------------------------------------------------------------------------------");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-07
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多