|
1,点击图片,然后看到下个数字,接下来再输入这个数字,如此循环
2,有400次这样的next数字,所以只有用程序了
3,因为不断跳转页面,所以这个程序运行耗时比较大
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
public class Challenge4HttpClient {
public static void main(String[] args) throws HttpException, IOException {
HttpClient client = new HttpClient();
String nothing = "12345";
for(int i = 0 ; i < 400; i++){
String url = getUrl(nothing);
GetMethod get = new GetMethod(url);
client.executeMethod(get);
String pageInfo = get.getResponseBodyAsString();
nothing = searchNothing(nothing, pageInfo);
get.releaseConnection();
}
}
private static String searchNothing(String nothing, String pageInfo) {
if(pageInfo.indexOf("Divide by two") != -1){
nothing = String.valueOf(Integer.valueOf(nothing)/2);
}else if(pageInfo.indexOf("the next nothing") != -1){
String[] strArr = pageInfo.split(" ");
nothing = strArr[strArr.length-1];
System.out.println(strArr[strArr.length-1]);
}else{
System.out.println("result = " + pageInfo);
}
return nothing;
}
private static String getUrl(String nothing) {
StringBuilder builder = new StringBuilder();
builder.append("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=");
builder.append(nothing);
System.out.println("builder string = " + builder.toString());
return builder.toString();
}
} |
|
|
|
|
|
|