0

我有一个链接列表,它们增加了一个我想采用字符串类型的 xpath 并将其拆分到数字所在的位置,并且每次循环时将该数字更改为一个。

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
 }   

请帮忙。

4

2 回答 2

1

根据我对您的问题的理解,解决方案如下:

         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...
        }
于 2013-10-22T18:59:21.447 回答
0

如果使用最新的 JDK (1.5+),请使用:

for (String chunk: vPath.split("/a")) {
    System.out.println(chunk);
    // and anything else with chunk here...
}

但是,在此之前,请阅读一本好的 Java 书籍并学习数组和集合。

于 2013-10-22T18:33:22.790 回答