java通过电话号码获取归属地,区号,邮编

1,需要jar包:jsoup-1.7.2.jar 或者其他版本

2,

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class NUmTest {
  public static void main(String[] args) throws Exception {

      String mobile = "xxxxxxxxxxx";  //电话号码
      String url = "http://www.ip138.com:8080/search.asp?action=mobile&mobile=%s";
      url = String.format(url, mobile);
      Document doc = Jsoup.connect(url).get();
      Elements els = doc.getElementsByClass("tdc2");
      System.out.println("归属地:" + els.get(1).text().replaceAll(" ", "-"));
      System.out.println("类型:" + els.get(2).text());
      System.out.println("区号:" + els.get(3).text());
      System.out.println("邮编:" + els.get(4).text().substring(0, 6));
}
}

你可能感兴趣的:(地图)