`
- 浏览:
164958 次
- 性别:
- 来自:
free-town
-
- 以下代码为抓取ip地址并入库分析,代码仅供参考,并未做任何处理....
public static void main(String[] args) {
String crawl_url = "http://www.cnblogs.com/xioxu/archive/2009/05/03/1448322.html";
StringBuilder sb = new StringBuilder();
try{
URL instance = new URL(crawl_url);
URLConnection con = instance.openConnection();
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String readLine;
while((readLine = bufferReader.readLine()) != null){
// cache in memory
sb.append(readLine);
}
}catch(Exception ex){
}
parseIp(sb.toString());
}
private static void parseIp(String html){
List<String> parseList = new ArrayList<String>();
String regex = "((\\d{2,}\\.){3}\\d{2,})\\__((\\d{2,}\\.){3}\\d{2,})\\__([^a-zA-Z]{2,})\\__([^a-zA-Z]{2,})";
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(html);
while(matcher.find()){
String str = matcher.group();
str = str.replaceAll("[\\<\\/]", "");
parseList.add(str);
System.out.println(str);
/*String startIp = matcher.group(0);
String endIp = matcher.group(1);
String province = matcher.group(2);
String routeType = matcher.group(3);
System.out.println("startIp: " + startIp + "\tendIp: " + endIp + "\tprovince: " + province + "\trouteType: " + routeType);*/
}
List<Ip> ipList = toIpList(parseList);
for(Ip ip : ipList){
System.out.println(ip.toString());
}
}
private static List<Ip> toIpList(List<String> list){
List<Ip> ipList = new ArrayList<Ip>();
Ip ip = null;
for(String line : list){
ip = new Ip();
String[] asArray = toIpArray(line);
ip.setStartIp(asArray[0]);
ip.setEndIp(asArray[1]);
ip.setProvince(asArray[2]);
ip.setRouteType(asArray[3]);
ipList.add(ip);
}
return ipList;
}
private static String[] toIpArray(String line){
String[] toArray = new String[5];
int pos = 0;
int length = "__".length();
int idx = 0;
while((pos = line.indexOf("__")) > -1){
String value = line.substring(0,pos);
toArray[idx++] = value;
line = line.substring(pos + length);
}
return toArray;
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
使用Jsoup抓取网页关键信息并入库 ip天气查询并发送邮件
一款很好用的代理IP抓取软件,可设定自动抓取代理IP的时间段,可设定开机启动,自动去重,自动存档,支持后台操作。
爬虫抓取京东价格 解析Json格式 对所有开发抓取京东价格人员非常有帮助。
抓取网页IP和端口并设置代理 可以抓取下面网页的IP和端口 http://www.cnproxy.com/proxy1.html 个人写着用的。
使用jsoup抓取网页列表信息,并入库,使用了PreparedStatement防止sql注入小demo。
根据输入的ip段获取ip所属地址信息
本文设计了一种web服务抓取解析器框架,包括URL抓取器,WSDL解析器和用于结构化存储web信息的数据库等。
php抓取ip138数据库的代码,在命令行下执行效率最高,经测试,网页下载速率可达700kb/s,数据库设计按照id、开始ip、结束ip、地址一、地址二设计,有效减小数据库体积,提高检索效率。使用时请先安装php及mysql
一个文件抓取免费的代理IP,验证后并存入mysql数据库,另一个文件循环排除已失效的IP,可用来创建自己的代理IP池
可以抓取网路中的所有ip包!可以方便学习者更直观的查看各种基于ip的协议。
在不知道设备地址的情况下,轻松获取ip地址,进行设备配置
通过Java网络爬虫爬取指定代理ip网上的ip,利用了jsoup、httpclient技术实现
本项目可以直接运行 实现监听网络 抓取网络数据包 分析 显示IP层数据,TCP/UDP 层数据 , 可指定IP 端口号 等
网络协议分析的课程设计,题目IP数据包解析,改程序的主要功能是抓取本地主机的IP数据包,并解析。
完全采用c语言编写,抓取ip数据报,分析ip数据包头!
基于Apache Nutch 1.8和Htmlunit组件,实现对于AJAX加载类型页面的完整页面内容抓取解析。 According to the implementation of Apache Nutch 1.8, we can't get dynamic ...
需要安装wxWidget模块 进程id读取用到了pywin32模块 抓包用到了WinPcap
淘宝IP获取器,采集淘宝提供的api接口中的全部IP库
功能超强的获取IP工具,不停止无限获取。
将中国天气网近六天(因为有些城市提供的接口只有五天数据,所以我暂时取5天,程序里依然是六天的标准)的天气情况抓取,用JSON解析,存入数据库,数据库是两张表,城市表和天气表。程序可以运行,两个表都能读入...