我有一个链接列表,它们正在增加 1,我想采用字符串类型的 xpath 并将其拆分到数字所在的位置,然后每次循环时将该数字更改为 1。
String vPath= "/html/body/section/section[2]/a[1]";
//so the number that's changing is in the last bracket
String[] t = vPath.split("/a");
然后我想使用分割变量并循环。所以也许使用 for 循环。但是,我似乎有一个问题,我该如何做到这一点。我觉得应该是这样的
For (int i=1; i < t(something here); i++{
then the code of clicking should go here
}
请大家帮忙。
最佳答案
根据我对您问题的理解,解决方案如下:
String vPath= "/html/body/section/section[2]/a[1]"; //sample url
int size = 100; // no of links you want to generate as per your requirement
String[] chunks = vPath.split("/a");
String chunk = chunks[0];
for(int index =1; index <= size;index++){
System.out.println(chunk+"["+index+"]"); // printing generated urls
//code of clicking...
}
关于java - 如何在java中循环解析已解析的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19525609/