
net.sf.weixinmp.thirdparty.PhoneAdressService Maven / Gradle / Ivy
The newest version!
package net.sf.weixinmp.thirdparty;
import java.io.IOException;
import java.net.URL;
import net.sf.weixinmp.thirdparty.model.Phone;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/*
* http://www.ip138.com:8080/search.asp?mobile=15050160243&action=mobile
* @author Mao, Anping
*
*/
public class PhoneAdressService {
public String PHONE_QUERY_URL="http://www.ip138.com:8080/search.asp";
private int timeoutMills=5000;
public Phone execute(String phoneNumber) throws IOException {
try {
Document doc=Jsoup.parse(new URL(PHONE_QUERY_URL+"?action=mobile&mobile="+phoneNumber), timeoutMills);
Elements tables=doc.select("table");
if(tables.size()<2) return null;
Element table=tables.get(1);
Elements trs=table.select("tr");
if(trs.size()!=6) return null;
Phone ret=new Phone();
String provc=trs.get(2).select("td").get(1).text();
if(provc==null||provc.isEmpty()) return null;
String pc[]=provc.split(" ");//全角空格
if(pc.length<2) return null;
ret.setPro(pc[0].replace("省", ""));
ret.setCity(pc[1].replace("市", ""));
String provider=trs.get(3).select("td").get(1).text();
ret.setServiceProvider(provider);
ret.setPhoneNumber(phoneNumber);
return ret;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) throws IOException {
PhoneAdressService service=new PhoneAdressService();
service.setTimeout(50000);
System.out.println(service.execute("18118163001"));
}
private void setTimeout(int mills) {
this.timeoutMills = mills;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy