正则表达式—网页爬虫
2014-07-11 20:05
239 查看
/** * @param args * 网页爬虫,其实就是一个程序用于在互联网中获取符合指定规则的数据 * @throws IOException */ public static void main(String[] args) throws IOException { List<String> mailList=test(); for(String mail:mailList){ System.out.println(mail); } } public static List<String> test() throws IOException{ //创建一个集合容器 List<String> list=new ArrayList<String>(); //创建一个URL对象,获取流 URL url=new URL("file:///E:/WorkspaceForJava/test1/myWeb.html"); BufferedInputStream bis=new BufferedInputStream(url.openStream()); //创建一个字节数组,将从网页中读取到的内容写到这个数组中 byte[] buf=new byte[1024*4]; int ch=0; while((ch=bis.read(buf))!=-1){ String text=new String(buf,0,ch); //编写邮编正则表达式 String regex="[a-zA-Z0-9_]+@[a-zA-Z]+(\\.[a-zA-Z]{1,3})+"; //将符合正则表达式的内容存到集合容器中 Pattern p=Pattern.compile(regex); Matcher m=p.matcher(text); while(m.find()){ String mail=m.group(); list.add(mail); } } return list; }
相关文章推荐
- 正则表达式实例 网页爬虫抓取页面邮箱地址
- 网页爬虫1--正则表达式
- 正则表达式:网页爬虫
- 爬虫的自我解剖(抓取网页HtmlUnit)
- 实习第一周做的事情 :就算是 网页爬虫吧
- Python爬虫(入门+进阶)学习笔记 1-8 使用自动化神器Selenium爬取动态网页(案例三:爬取淘宝商品)
- 网页爬虫汇总
- 爬虫解决网页重定向问题
- python爬虫解析网页编码问题
- Python3简单爬虫抓取网页图片
- Python使用爬虫爬取静态网页图片的方法详解
- python网页爬虫
- 多线程获取豆瓣网页的网络爬虫(Python实现)
- Python网页爬虫
- Python开发中爬虫使用代理proxy抓取网页的方法示例
- 使用HttpWebRequest和HtmlAgilityPack抓取网页(拒绝乱码,拒绝正则表达式)
- 关于爬虫的,获得网页源代码
- 浏览网页访客和搜索引擎爬虫不同的Agent 内容
- Python爬虫爬取一个网页上的图片地址实例代码
- 网络爬虫:使用多线程爬取网页链接