Jsoup根据颜色获取数据表格

时间:2017-06-02 08:48:07

标签: java xml jsoup

我需要从表格http://www.mercado.ren.pt/EN/Electr/MarketInfo/Interconnections/CapForecast/Pages/Daily.aspx

获取数据(实际 - 灰色和预测容量 - 绿色)

我正在使用Jsoup,我不知道如何根据颜色获得容量。最糟糕的是我甚至无法在XML中找到颜色。

HTML代码如下所示:

<table class="gridALL" cellspacing="0" cellpadding="2" border="0">
  <tr>
    <th align="left" colspan="2">
      <A id='helpTimePeriod' href='/EN/pages/TimePeriods.aspx' target='_blank'>
        <span class='txtDATA'>HOURS</span>
        <span style='vertical-align: 13%;' class='icon-info'>&nbsp;</span>
      </A>
    </th>
    <th align="left" valign="middle" colspan="29">Import Capacity</th>
  </tr>
  <tr class="tabHEADER">
    <th class="rbcellBDRCOLOR" align="right" scope="col">HOUR</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">26&nbsp;May</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">27&nbsp;May</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">28&nbsp;May</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">29&nbsp;May</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">30&nbsp;May</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">31&nbsp;May</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">01&nbsp;Jun</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">02&nbsp;Jun</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">03&nbsp;Jun</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">04&nbsp;Jun</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">05&nbsp;Jun</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">06&nbsp;Jun</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">07&nbsp;Jun</th>
    <th class="rbcellBDRCOLOR" align="right" scope="col">08&nbsp;Jun</th>
    <th class="bcellBDRCOLOR" align="right" scope="col">09&nbsp;Jun</th>
  </tr>
  <tr class="trPAR">
    <td class="rcellBDRCOLOR" align="right" width="50">1</td>
    <td class="txtrVERIF" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2700</td>
    <td class="txtrPREV" align="right" width="60">2400</td>
    <td class="txtrPREV" align="right" width="60">2400</td>
    <td class="txtrPREV" align="right" width="60">2400</td>
    <td class="txtrPREV" align="right" width="60">2400</td>
    <td class="txtrPREV" align="right" width="60">2400</td>
    <td class="txtrPREV" align="right" width="60">2400</td>
    <td class="txtPREV" align="right" width="60">2400</td>
  </tr>

是否可以使用Jsoup lib获取此字段?

编辑:

到目前为止,我有这个,现在:

doc = Jsoup.connect(path).get();
for (Element table: doc.select("table.gridALL")) {
  for (Element row: table.select("tr")) {
    Elements tds = row.select("td");
    if (tds.size() >= 16) {
      String record = tds.get(column).text();
      String recordColor = tds.get(column).attr("class");

我只能获得属性(txtrVERIF / txtrPREV)或容量。如何根据属性获取容量?我应该给出什么条件?

0 个答案:

没有答案