2013-09-29 32 views
0

我想從我的代碼在下面的網站獲取信息,該網站有一個表,並在該表中是一個特定區域的「潮汐」時間,當我嘗試使用jsoup爲了得到這個時間它返回數據的分配,但沒有一個是我想要的時間。什麼選擇器用於Jsoup

如何選擇該數據?

代碼:

docTide = 
    Jsoup.connect(
    "http://www.tide-forecast.com/locations/Falmouth-England/tides/latest") 
     .timeout(600000).get(); 
Elements tideTableRows = docTide.select("table.tide tr:eq(1), td:eq(1)"); 
tideTimes = tideTableRows.text(); 
System.out.println(tideTimes); 

回答

1

id="Tide"表填充在Javascript中,JSoup報告靜態DOM,而不是動態的。解決您的問題的另一種方法是在您的瀏覽器中使用附件來調查由Javascript支持的「實時」DOM。

<div align="center" class="not_in_print"> 
<h2>Today's tide times for Falmouth, England</h2> 
<table id="tide"> 
    <tr> 
    <th>&nbsp;</th> 
    <th>Time now:</th> 
    <th>Next HIGH tide</th> 
    <th>Next LOW tide</th> 
    </tr> 
    <tr> 
    <th>Local time</th> 
    <td><input type="text" value="" name="localtime" id="localtime"/></td> 
    <td><input type="text" value="" name="hightime" id="hightime"/></td> 
    <td><input type="text" value="" name="lowtime" id="lowtime"/></td> 
    </tr> 
    <tr> 
    <th>Countdown</th> 
    <td>&nbsp;</td> 
    <td><input type="text" value="" name="highcountdown" id="highcountdown"/></td> 
    <td><input type="text" value="" name="lowcountdown" id="lowcountdown"/></td> 
    </tr> 
</table> 

資源:

+0

您好,感謝您的回答。我想知道是不是因爲桌面正在更新,對於我不確定的編程新手而言。由於Jsoup無法使用,您提到了瀏覽器調查Feed的「附加功能」,這是否需要在每次訪問網頁時完成?因爲這是作爲一個Android應用程序的目的,所以會有一個庫可用,你知道這個主題的任何教程?它開始聽起來像只訪問泰晤士報的靜態表格會更好,但我確實喜歡挑戰。謝謝 –

+0

發佈更新與鏈接(谷歌關於詞的Chrome附加擴展DOM) – Aubin

+0

感謝您的更新答案。 –