2017-08-28 100 views
0

我有表分析,其裝有AJAX一個問題:Jsoup,解析HTML載入AJAX表

Document doc = Jsoup.connect("http://lfl.ru/club553").get(); 

這就是我得到:

<div class="tournament_stats_table_tournament_3442 tournament-stats-table" style="display: block;" url="/?ajax=1&amp;method=tournament_stats_table&amp;tournament_id=3442&amp;club_id=553"> 
         подождите...     </div> 

請告訴我什麼都可以在這種情況下完成。 Thx。

+1

的可能的複製[頁內容加載javascript和Jsoup沒有看到它(https://stackoverflow.com/questions/7488872/page-content-is-loaded-with-javascript-and -jsoup-doesnt-see-it) – luksch

回答

0

您將無法使用服務器 - >服務器請求獲取數據。當你在服務器上做你的請求時,JS將不會被執行,因此表格根本不可用。

作爲替代想想這些:

  1. 如果你的網站的,你解析所有者 - 嘗試儘可能地避免AJAX;
  2. 檢查ajax請求的端點是什麼,並簡單地解析它而不是網頁;
+0

感謝您的回答。 我不是網站所有者,我需要在我的網站上自動更新此表的過程。 –

+1

@ivanVishnyak檢查ajax請求並解析它的結果。 –

0

首先:你需要得到餅乾,只是用

Connection.Response = Jsoup.connect.method(get).excute 

然後:做與cookie和頭

document=Jsoup.connect.header.data.post 

例如要求

Connection.Response loginForm=Jsoup.connect("http://www.a5.cn"). 
     method(Connection.Method.GET).execute(); 

Document document=Jsoup.connect("http://www.a5.cn/login.html"). 
     data("formhash","97bfbf").data("hdn_refer","http://www.a5.cn/") 
     data("account","userID").data("autoLogin","1").data("password","your password"). 
     cookies(loginForm.cookies()).header("Accept","application/json, text/javascript, */*; q=0.01").header("X-Requested-With","XMLHttpRequest").post(); 

System.out.println(document.body().text());