Java 如何获取表的前3个td值?

Java 如何获取表的前3个td值?,java,jsoup,Java,Jsoup,我正在下表中进行数据报废 <table width="100%" class="indexes"> <thead> <tr> <th></th> <th>Last</th> <th>Chg</th> <th>Chg %</th> <th>High&

我正在下表中进行数据报废

<table width="100%" class="indexes">
   <thead>
      <tr>
         <th></th>
         <th>Last</th>
         <th>Chg</th>
         <th>Chg %</th>
         <th>High</th>
         <th>Low</th>
      </tr>
   </thead>
   <tbody>
      <tr class="alt">
         <td class="indexes-arrow">
            <div class="arrow_positive"></div>
         </td>
         <td class="indexprice fleft positive">7,851.50</td>
         <td class="indexchange  fleft positive">+0.50</td>
         <td class="indexpercent  fleft positive">+0.01%</td>
         <td class="indexhigh fleft">7,888.50</td>
         <td class="indexlow fleft">7,818.00</td>
      </tr>
   </tbody>
</table>
但是它是空的,您能告诉我如何获取前3个td值吗


你能告诉我如何解决这个问题吗?

试着按他们的类别选择他们

e1 = doc.select("td.indexprice").text();
e2 = doc.select("td.indexchange").text();
e3 = doc.select("td.indexpercent").text();
解决方案 这里更简单,因为每个标记都有以下类
positive

for (Element e : doc.getElementsByClass("positive")){
    System.out.println(e.text());
}

您也可以使用索引进行选择

e1 = doc.select("tr td:nth-child(2)").text();
e2 = doc.select("tr td:nth-child(3)").text();
e3 = doc.select("tr td:nth-child(4)").text();
e1 = doc.select("tr td:nth-child(2)").text();
e2 = doc.select("tr td:nth-child(3)").text();
e3 = doc.select("tr td:nth-child(4)").text();