zoukankan      html  css  js  c++  java
  • java 获取手机归属地,引起net.UnknownHostException错误

    这个问题是请求,重定向了,跟入源码。修改了地址,变成302

                    Connection connect = Jsoup.connect(url);
    	        connect.header("Host", "http://info.bet007.com");
    	        connect.header("User-Agent", "  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0");
    	        connect.header("Accept", "  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    	        connect.header("Accept-Language", "zh-cn,zh;q=0.5");
    	        connect.header("Accept-Charset", "  GB2312,utf-8;q=0.7,*;q=0.7");
    	        connect.header("Connection", "keep-alive");
    			
    	        Document doc = connect.get();
    

      就可以获取到手机归属地了

    	public static String[] getPhoneAddressAndCompanyStrs(String phone){
    		if(phone.length()<=0)
    			return null;
    		String url = "http://www.ip138.com:8080/search.asp?action=mobile&mobile=%s";
    		url = String.format(url, phone);
    		
    		String[] strs=new String[2];
    		try {
    			Connection connect = Jsoup.connect(url);
    	        connect.header("Host", "http://info.bet007.com");
    	        connect.header("User-Agent", "  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0");
    	        connect.header("Accept", "  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    	        connect.header("Accept-Language", "zh-cn,zh;q=0.5");
    	        connect.header("Accept-Charset", "  GB2312,utf-8;q=0.7,*;q=0.7");
    	        connect.header("Connection", "keep-alive");
    			
    	        Document doc = connect.get();
    			
    			Elements els = doc.getElementsByClass("tdc2");
    			int elsSize = els.size();
    			if(elsSize == 2) {
    				strs[0]=els.get(1).text();
    			}else if(elsSize > 2) {
    				strs[0]=els.get(1).text();
    				strs[1]=els.get(2).text();
    			}
    			return strs;
    		} catch (IOException e) {
    			
    			e.printStackTrace();
    			return null;
    		}
    	}
    

      

  • 相关阅读:
    最小生成树(卡鲁斯卡尔)
    最小生成树(kruskal模版 Prim模板)
    hdu1247(Hat’s Words)
    hdu1671Phone List(字典树)
    hdu1305Immediate Decodability(字典树)
    hdu1251(统计难题)
    oj1500(Message Flood)字典树
    oj2892(字典树)
    数论公式
    2504(多项式求和)
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/11024957.html
Copyright © 2011-2022 走看看