套用网上来查询手机归属地

下面两个包见我的空间资源 handy.jar,log4j.jar

HttpConnection 通过使用网页上的查询功能,提交 setRequestMethod(HttpConnection.REQUEST_METHOD_GET);
....

 

 

import java.util.HashMap;

import com.handy.socket.HttpConnection;
import com.handy.util.FileTool;

public class MobileCity {

    public MobileCity() {
        super();
    }

    public static void main(String[] args) {
     HttpConnection hc = new  HttpConnection();
     StringBuffer sb = new StringBuffer();
     String fileName="d:\\m.txt";
     String ms = FileTool.readFileToString(fileName);
     String[] _mss = ms.split("\n");
     int i=0;
     for (String m:_mss){
      m=m.trim();
      i++;
      //System.out.println(i+"."+m);
      
      //手机号归属地
         //String m="18017122529";
      String url="http://www.shoujichahao.com/search.jsp?numb="+m;
      System.out.println(url);
         hc.setRequestMethod(HttpConnection.REQUEST_METHOD_GET);
         hc.setUrl(url);
         hc.setCharset("utf-8");
         hc.setStartLine(69);
         hc.setEndLine(91);
         String str = hc.getHttpText();
         str = str.replace("&nbsp;", "").replaceAll("<[^>]+>", "").replace("归属地", "").replace("手机卡","");
         
         //System.out.println(str);
         
         HashMap<String,String> areacode = new HashMap<String,String>();
         
         String[] lines = str.split("\n");
         
         int nu=1;
         for (String line:lines){
          line = line.trim();
          if (!"".equals(line)){
           if (nu>2) break;
           System.out.println(line);
           if (line.indexOf(" ")>0){
            String[] ab = line.split(" ");
         areacode.put("Province", ab[0]);
         areacode.put("City", ab[1]);
           }else{
            areacode.put("Card", line);
           }
           nu++;
          }
         }
         
         String sql = "update sendsms_jian30 set province='"+areacode.get("Province")+"',city='"+areacode.get("City")+"',card='"+areacode.get("Card")+"' where addresses='tel:"+m+"'";
         if (areacode.get("Card")!=null) sb.append(sql+"\r\n");
         System.out.println(i+":"+sql);
         try {
    Thread.sleep(100);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
      
     }
     fileName = "d:\\m_city.sql";
     FileTool.writeStringToFile(fileName, sb.toString());
     
    }
    
   }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值