2013-09-29 27 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

感谢您的更新答案。 –