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);

带有id="Tide"的表在Javascript中填充,JSoup报告静态DOM,而不是动态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>

资源:

  • Chrome-developer-tools
  • google-chrome-extension-manipulation-dom-of-open-or-current-tab

最新更新