URL-https://www.etmoney.com/mutual-funds/equity/focused/77

在特定的网站上,我必须避开所有的基金规模,并将所有规模相加,稍后使用TestNG断言进行比较. 挑战在于基金规模有多个分隔符(₹和空格)3分隔符

对于ex:(刮刮基金规模)

₹110CRS

₹8,696个CRS

₹3,460个CR

₹711CRS

₹5,990 CRS

₹26,218 CRS

₹7,907 CRS

₹1,780个CRS

₹956 CRS

₹1,708个CR

₹1,330 CRS

₹5,825 CRS

₹18,712 CRS

最终输出类似于

110 
8696
3460
711
5990
26218
7907
1780
956 
1708
1330
5825
18712
int total = 0;
        List<WebElement> totalFunds = driver.findElements(By.xpath("//div[@class='card-bordy']/div/div/div/div/div[2]/div/div/div[2]/div/p[2]"));

for(int i=0;i<totalFunds.size();i++) {
            String funds = totalFunds.get(i).getText();
            String fu = funds.split(" ")[0];
            System.out.println(fu.split("₹")[1]);

错误-"java.lang.ArrayIndexOutOf边界异常:索引%1超出长度%1的界限"

推荐答案

您可以在此处使用正则表达式替换/捕获方法:

int total = 0;
List<WebElement> totalFunds = driver.findElements(By.xpath("//div[@class='card-bordy']/div/div/div/div/div[2]/div/div/div[2]/div/p[2]"));

for (int i=0;i < totalFunds.size(); i++) {
    String funds = totalFunds.get(i).getText();
    String fu = funds.replaceAll(".*?(\\d{1,3}(?:,\\d{3})*).*", "$1");
    System.out.println(fu);
}

Java相关问答推荐

Junit with Mockito for java

Spring Boot@Cachebale批注未按预期工作

当我已经安装了其他版本的Java时,如何在Mac OSX 14.3.1上安装Java 6?

名称冲突具有相同的擦除

使用REST客户端和对象映射器从字符串反序列化Json

JDK 21-为什么线程局部随机S nextInt不直接用Super.nextInt实现?

Kotlin Val是否提供了与Java最终版相同的可见性保证?

基于配置switch 的@Controller的条件摄取

Spring Framework6.1中引入的新RestClient是否有适合于测试的变体,就像RestTemplate和TestRestTemplate一样?

如何在Record Java中使用isRecord()和RecordComponent[]?

在Oracle中调用输出参数在索引处缺少IN或OUT参数的函数

如何将RESTAssured';S的Http标题转换为<;字符串、字符串和>的映射?

如何在Spring Security中设置一个任何人都可以打开的主页?

Intellij 2023 IDE:始终在顶部显示菜单栏

为什么Instant没有从UTC转换为PostgreSQL的时区?

[Guice/MissingImplementation]:未绑定任何实现

JavaFX AnchorPane zoom

当小数位数已知时,BigDecimal 除法有缺点吗?

如何在 Java 中使用纪元时间和时区查找一天的结束时间

升级到Spring Boot 3后mapstruct生成的文件中的Javax依赖