爬虫, 获取登录者的外网IP

 

笔者学习了一下用爬虫, 获取登录者的外网IP。

 

首先导入Jsoup的jar包

 

public class RetrivePage {

private static String url="http://www.ip.cn/";

/** 连接网站,模拟浏览器登陆,避免网站识别为手机进入 */
private static final String USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0";


/**设置超时时间 */
private static final int timeout=50000;



/**
* @param args
*/
public static void main(String[] args) {

try {
Document doc=Jsoup.connect(url).userAgent(USERAGENT).timeout(timeout).get();

Elements elements=doc.select("#result .well ");
if(elements !=null && elements.size()>0){
for (Element e:elements) {
//System.out.println(e.select("p ").text());

System.out.println("我的远程IP:"+e.select("p code").text());
System.out.println(e.select("p ").text());
}
}

} catch (IOException e) {
e.printStackTrace();
}

}

}

 

 

到此为止,主要为自己做备忘,同时方便有需要的人。呵呵!

posted @ 2014-09-15 10:30  江湖小谢*VIP  阅读(608)  评论(0编辑  收藏  举报