2017-06-13 3 views
0

を使用する:https://demo.tutorialzine.com/2009/09/simple-ajax-website-jquery/demo.html#page3私はHtmlUnitを搭載しprerendererを構築しようとしているし、次のURLでそれをテストしようとしたんだHtmlUnitプリレンダリングJavascriptのウェブサイトへ(HTMLスナップショット)

は、ここに私のコードです:

  final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED); 
      WebClientOptions options = webClient.getOptions(); 
      options.setCssEnabled(true); 
      webClient.setCssErrorHandler(new SilentCssErrorHandler()); 
      webClient.setAjaxController(new NicelyResynchronizingAjaxController()); 
//   webClient.setAjaxController(new AjaxController(){ 
//    @Override 
//    public boolean processSynchron(HtmlPage page, WebRequest request, boolean async) { 
//     return true; 
//    } 
//   }); 
      options.setThrowExceptionOnScriptError(false); 
      options.setThrowExceptionOnFailingStatusCode(false); 
      options.setRedirectEnabled(false); 
      options.setAppletEnabled(false); 
      options.setJavaScriptEnabled(true); 
      //options.setUseInsecureSSL(true); 
      options.setTimeout(50000); 
      webClient.addRequestHeader("Access-Control-Allow-Origin", "*"); 

      HtmlPage page = webClient.getPage(path); 

      // important! Give the headless browser enough time to execute JavaScript 
      // The exact time to wait may depend on your application. 
      webClient.setJavaScriptTimeout(10000); 
      webClient.waitForBackgroundJavaScript(10000); 
      //just wait 
      for (int i = 0; i < 20; i++) { 
       synchronized (page) { 
        page.wait(500); 
       } 
      } 
      String xml = page.asXml(); 

ここでの問題は、出力HTMLにJavascriptで取り込む必要があるコンテンツが含まれていないことです。

ここで間違っていますか?

答えて

0

さて、以下のコードは、2.28-snapshotで取得:マッサVEL lectus aliquam laoreet NECで

Donecらturpis。 ....

try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) { 
     WebClientOptions options = webClient.getOptions(); 
     options.setCssEnabled(true); 
     webClient.setAjaxController(new NicelyResynchronizingAjaxController()); 
     options.setTimeout(50000); 
     webClient.addRequestHeader("Access-Control-Allow-Origin", "*"); 

     HtmlPage page = webClient.getPage("https://demo.tutorialzine.com/2009/09/simple-ajax-website-jquery/demo.html#page3"); 

     // important! Give the headless browser enough time to execute JavaScript 
     // The exact time to wait may depend on your application. 
     webClient.setJavaScriptTimeout(10000); 
     webClient.waitForBackgroundJavaScript(10000); 
     //just wait 
     Thread.sleep(10000); 

     String xml = page.asXml(); 
     System.out.println(xml); 
    } 

あなたは他に何が欠けていますか?

関連する問題