gpt4 book ai didi

java - 当表呈指数减少时,如何仅迭代每行的最后一列数据

转载 作者:行者123 更新时间:2023-12-01 08:57:26 26 4
gpt4 key购买 nike

我有一个包含 tr 和 td 的 HTML 表。这些值根据给定的日期选择进行更改。我需要迭代每一行、最后一列数据并添加它们。每行该值减一。请帮助我,如何仅获取每行的最后一列数据。该图像附在下面并突出显示。

ClickHere

HTML code
<div class="row">
<div id="installCohort" class="col-md-12">
<div class="cornelius-container">
<table class="cornelius-table">
<tr>
<th class="cornelius-time">Time</th>
<th class="cornelius-people">Installs</th>
<th class="cornelius-people">1</th>
<th class="cornelius-people">2</th>
<th class="cornelius-people">3</th>
<th class="cornelius-people">4</th>
<th class="cornelius-people">5</th>
</tr>
<tr>
<td class="cornelius-label">October 2016</td>
<td class="cornelius-people">3</td>
<td class="cornelius-absolute cornelius-extra-hot" title="3">3</td>
<td class="cornelius-absolute cornelius-medium-high" title="1">1</td>
<td class="cornelius-absolute cornelius-low">0</td>
<td class="cornelius-absolute cornelius-low">0</td>
**<td class="cornelius-absolute cornelius-low">0</td>**
</tr>
<tr>
<td class="cornelius-label">November 2016</td>
<td class="cornelius-people">16056</td>
<td class="cornelius-absolute cornelius-hot" title="10790">10790</td>
<td class="cornelius-absolute cornelius-high" title="7861">7861</td>
<td class="cornelius-absolute cornelius-high" title="7186">7186</td>
**<td class="cornelius-absolute cornelius-high" title="7186">7186</td>**
<td class="cornelius-empty">-</td>
</tr>
<tr>
<td class="cornelius-label">December 2016</td>
<td class="cornelius-people">85254</td>
<td class="cornelius-absolute cornelius-high" title="38098">38098</td>
<td class="cornelius-absolute cornelius-medium-high" title="33857">33857</td>
**<td class="cornelius-absolute cornelius-medium-high" title="33790">33790</td>**
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
</tr>
<tr>
<td class="cornelius-label">January 2017</td>
<td class="cornelius-people">24814</td>
<td class="cornelius-absolute cornelius-high" title="14883">14883</td>
**<td class="cornelius-absolute cornelius-high" title="14839">14839</td>**
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
</tr>
<tr>
<td class="cornelius-label">February 2017</td>
<td class="cornelius-people">227</td>
**<td class="cornelius-absolute cornelius-extra-hot" title="226">226</td>**
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
</tr>
<tr>
<td class="cornelius-label">March 2017</td>
**<td class="cornelius-people">0</td>**
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
<td class="cornelius-empty">-</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

如果您看到上图,这些值呈指数递减,甚至元素标签也发生变化,如 cornelius-low、cornelius-high、cornelius-medium 等。

我尝试了下面的代码保持循环。由于元素标签发生变化,无法仅获取 0, 7186, 33790, 14839, 226

最佳答案

尝试使用以下代码获取每个tr的最后一个td:

List<WebElement> rows = driver.findelements(By.xpath('//table[@class="cornelius-table"]//tr[not(th)]'));
Iterator<WebElement> iter = rows.iterator();
while(iter.hasNext()) {
WebElement tr = iter.next();
td = tr.findelement(By.xpath('./td[not(@class="cornelius-empty")][last()]'));
System.out.println(td.getText());
}
}

关于java - 当表呈指数减少时,如何仅迭代每行的最后一列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41955462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com