因为公司一项目想做个手机号码归属地查询,没有现成的号码段库,要我从网上攫抓取,所以我从网上找了些资料,修改了下,得到如下代码,是可以用了的,但是由于频繁访问,没一会IP就被限制用不了了,所以想用代理,公司正好有几台代理,各位大哥帮我修改一下,我学JAVA没多久,还是边学边用的,能帮我修改一下吗,代理IP地址有五个,最好搞个配置放在XML配置文件上,谢谢了!
太急用了,搞了两天了!!package mobileFromUtil;import java.io.BufferedReader;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
/**   
 * 通过手机号码,获得该号码的归属地   
 *   
 * @author Administrator   
 *  
 */   
public class MobileFromUtil {   
  //正则表达式,抽取手机归属地   
  public static final String REGEX_GET_MOBILE= "(?is)<td.*?>您查询的手机号码段</td>.*?<td.*?>(.*?)</td>.*?<td.*?>卡号归属地</td>.*?<td.*?>(.*?)</td>.*?<td.*?>卡&nbsp;类&nbsp;型</td>.*?<td.*?>(.*?)</td>";   
  //正则表达式,审核要获取手机归属地的手机是否符合格式,可以只输入手机号码前7位   
  public static final String REGEX_IS_MOBILE=   
  "(?is)(^1[3|4|5|8][0-9]\\d{4,8}$)";   
    
  /**   
  * 获得手机号码归属地   
  *   
  * @param mobileNumber   
  * @return   
  * @throws Exception   
  */   
  public static String getMobileFrom(String mobileNumber) throws Exception {   
  if(!veriyMobile(mobileNumber)){   
  throw new Exception("不是完整的11位手机号或者正确的手机号前七位");   
  }   
  HttpClient client=null;   
  PostMethod method=null;   
  NameValuePair mobileParameter=null;   
  NameValuePair actionParameter=null;   
  int httpStatusCode;   
    
  String htmlSource=null;   
  String result=null;   
    
    
  try {   
  client=new HttpClient();   
  client.getHostConfiguration().setHost("www.ip138.com", 8080, "http");   
  method=new PostMethod("/search.asp");   
  mobileParameter=new NameValuePair("mobile",mobileNumber);   
  actionParameter=new NameValuePair("action","mobile");   
  method.setRequestBody(new NameValuePair[] { actionParameter,mobileParameter });   
  //设置编码   
  method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GB2312");   
  client.executeMethod(method);   
  httpStatusCode=method.getStatusLine().getStatusCode();   
  if(httpStatusCode!=200){
  throw new Exception("网页内容获取异常!Http Status Code:"+httpStatusCode);   
  }   
    
  htmlSource=method.getResponseBodyAsString();   
// System.out.println("一、"+htmlSource);
    
  if(htmlSource!=null&&!htmlSource.equals("")){   
  result=parseMobileFrom(htmlSource);   
    
  }   
  } catch (RuntimeException e) {   
    
  e.printStackTrace();   
  }finally{   
  method.releaseConnection();   
  }   
    
  return result;   
    
  }   
    
    
  /**   
  * 从www.ip138.com返回的结果网页内容中获取手机号码归属地,结果为:省份 城市   
  *   
  * @param htmlSource   
  * @return   
  */   
  public static String parseMobileFrom(String htmlSource){   
  Pattern p1 = null;   
  Matcher m1 = null;   
  String result = null;   
    
// StringBuffer sb = new StringBuffer();  
  htmlSource = htmlSource.replaceAll("<!--.*?-->","");
  p1 = Pattern.compile(REGEX_GET_MOBILE);   
  m1 = p1.matcher(htmlSource);   
    
    
  if(m1.find()){
  System.out.println(m1.group(1)+","+m1.group(2).replace("&nbsp;", ",")+","+m1.group(3));
  }  
  
    
    
  return result;   
    
  }   
    
  /**   
  * 验证手机号   
  * @param mobileNumber   
  * @return   
  */   
  public static boolean veriyMobile(String mobileNumber){   
  Pattern p=null;   
  Matcher m=null;   
    
  p=Pattern.compile(REGEX_IS_MOBILE);   
  m=p.matcher(mobileNumber);   
    
  return m.matches();   
  }   
    
  /**   
  * 测试   
  * @param args   
  * @throws Exception   
  */   
  public static void main(String[] args) throws Exception {  
  try{
  BufferedReader br = new BufferedReader(new FileReader("tel7.data"));
  
  String s = null;
  String info = null;
  while((s = br.readLine()) != null){
  Thread.sleep(1000*20);
  info = getMobileFrom(s);
  System.out.println(info);
  BufferedWriter bw = new BufferedWriter(new FileWriter("phoneinfo.data",true));
  bw.write("\n"+info);
  bw.flush();
  bw.close();
  }
  
  br.close();
  
  }catch(Exception e){
  e.printStackTrace();
  } }       
}   公司里用的代理器是CCProxy.v6.5.0这个,但是我不知道怎么在我的代码里调用代理,怎么设置才能用