简体   繁体   English

Jsoup使用什么选择器

[英]What Selector to use for Jsoup

I am trying to gain the information from the website in my code below, The website has a table and in that table is the "Tide" times for a particular area, when I try to use jsoup to get that time it returns allot of data but none of it is the time I want. 我试图在下面的代码中从网站获取信息,该网站有一个表,并且该表中是特定区域的“潮汐”时间,当我尝试使用jsoup获取该时间时,它将返回数据分配但这不是我想要的时间。

How do I select that data? 如何选择该数据?

Code: 码:

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

The table with id="Tide" is filled in Javascript, JSoup report the static DOM, not the dynamic one. id="Tide"的表用Javascript填充,JSoup报告静态DOM,而不是动态DOM。 Another way to solve your problem is to use an add-on to your browser to investigate into 'live' DOM feeded by Javascript. 解决问题的另一种方法是在浏览器中使用加载项来调查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>

Resources: 资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM