gpt4 book ai didi

java - 仅从父级 获取文本

转载 作者:行者123 更新时间:2023-11-30 04:01:56 25 4
gpt4 key购买 nike

在网站中它有这样的页脚

<td class=resutinfo >
Displaying 1 - 10 of 41 records Results per page:
<select onchange="javascript:gotoRow(1);" name="pageSize>
<option value=10, selected="true> 10 </option>
<option value=20, > 20 </option>
<option value=10, > 30 </option>
</select>
</td>

问题:

当我使用getText()时为此<td> ,它显示的值是这样的

Displaying 1 - 10 of 41 records Results per page: 10 20 30

但我只需要我不想要的意思,选择选项。

Displaying 1 - 10 of 41 records Results per page:

请您提供如何仅获取该字符串的建议。

最佳答案

这个想法是你得到文本 <td class="resutinfo">首先,应该是

Displaying 1 - 10 of 41 records Results per page: 10 20 30

然后你会得到 <select> 的文本,这应该是

10 20 30

然后将其替换为空字符串以删除。

String tdText = driver.findElement(By.xpath(".//td[@class='resutinfo']")).getText();
String selectText = driver.findElement(By.xpath(".//td[@class='resutinfo']/select")).getText();
tdText.replace(selectText, "").trim();

关于java - 仅从父级 <td> 获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21770373/

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