【问题标题】:What Selector to use for JsoupJsoup 使用什么选择器
【发布时间】:2013-09-29 08:28:06
【问题描述】:

我试图在下面的代码中从网站获取信息,该网站有一个表格,在该表格中是特定区域的“潮”时间,当我尝试使用 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);

【问题讨论】:

    标签: java android parsing selector jsoup


    【解决方案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>
    

    资源:

    【讨论】:

    • 您好,感谢您的回答。我想知道这是否是因为表格正在更新,我不确定是否是编程新手。由于无法使用 Jsoup,您提到了一个“插件”供浏览器调查提要,每次访问网页时都需要这样做吗?因为这是一个 android 应用程序,所以会有一个可用的库,你知道关于这个主题的任何教程吗?听起来似乎只为 Times 访问静态表会更好,但我确实喜欢挑战。谢谢
    • 用链接更新帖子(谷歌关于文字 Chrome 插件扩展 DOM)
    猜你喜欢
    • 2013-11-25
    • 2016-01-03
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    • 2011-12-20
    • 2013-09-15
    • 1970-01-01
    • 2012-07-05
    相关资源
    最近更新 更多