gpt4 book ai didi

java - XPATH - 如何从网页获取文本?

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

我需要使用 XPATH 从网页中选择特定文本。我的文本如下所示

The "Add Account Offer" request has been submitted successfully with the order number css_334560.

在上面的行中,我只需要使用 XPATH 获取“css_334560”。有人可以帮我吗?

HTML:-

<div id="secondColumn" class="floatBreaker">
<div id="mainContents">
<h1>Add Account Offers </h1>
<div class="infoBox">
<div class="topLine">
<div class="txtLineRight">
<div class="txtLineLeft">
<div class="txt">
<span>The "Add Account Offer" request has been submitted successfully with the order number css_334560.</span>
</div>
</div>

最佳答案

如果您使用Java,则可以使用以下代码:

String a = driver.findElement(By.xpath("//div[@class='txt']/span")).getText(); 
a = a.substring(a.lastIndexOf(' ') + 1).replace(".", "");

第一行从跨度获取文本。第二行采用 css_334560. 并删除点。

Html代码不完整,所以我不能保证xpath是正确的。

关于java - XPATH - 如何从网页获取文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23062268/

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