我想你应该是想通过这个页面的url来得到这个网页里面的某些数据把。用HttpClient 。
下面我这个方法是得到搜狗页面命中多少条记录的代码。
public static void main (String args[]){
String sRequestUrlString="
http://www.sogou.com/web?query=ondblclick %3D%22%22";
GetMethod getMethod = new GetMethod(sRequestUrlString);
HttpClient client = new HttpClient();
client.setConnectionTimeout(1000 * 60);
int status=0;
try {
status = client.executeMethod(getMethod);
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String sResponse="";
if(status==HttpStatus.SC_OK) {
sResponse=(getMethod.getResponseBodyAsString());
} else {
System.out.println("检索失败");
}
getMethod.releaseConnection();
String regExData = "找到 ([,\\d]*) 个网页";
if(sResponse!=null && sResponse.trim().length()>0) {
Pattern pattern = Pattern.compile(regExData);
Matcher matcher = pattern.matcher(sResponse);
if(matcher.find()) {
if(matcher.groupCount()>=1) {
int iTmpInteger =
Integer.parseInt(matcher.group(1).replaceAll(",",""),10);
System.out.println("找到"+iTmpInteger+"个网页");
}
}
}
}
这段测试代码是来测试搜狗的,String sRequestUrlString="
http://www.sogou.com/web? query=ondblclick%3D%22%22";
这里是拼写好的检索的url,
sResponse=(getMethod.getResponseBodyAsString());这个是得到本页面的源文件,然后通过
String regExData = "找到 ([,\\d]*) 个网页";正则表达式来获取([,\\d]*) ,得到命中的条数。