67,513
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
String ip="14.147.43.45";
String url = "http://www.ip138.com/ips.asp";
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
method.setParameter("ip", ip);
method.getParams().setContentCharset("GBK");
try {
client.executeMethod(method);
int statecode = method.getStatusCode();
if (statecode == HttpStatus.SC_OK) {
String temp=method.getResponseBodyAsString();
String rex = "<li>.*</li>";
Pattern p = Pattern.compile(rex);
Matcher m = p.matcher(temp);
if(m.find()){
System.out.println(m.group());
}
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}