zoukankan      html  css  js  c++  java
  • java爬虫--使用正则表达式获取网页中的email

    package com.enation.newtest;
    import java.io.*;
    import java.util.regex.*;
    import java.net.*;
    
    public class  MailTest{
         public static void main(String[] args) throws Exception{
             getMailAddr();
         }
    
         public static void getMailAddr()throws Exception{
             URL url=new URL("http://blog.sina.com.cn/s/blog_515617e60101e151.html");
             URLConnection con=url.openConnection();
    
             BufferedReader bufIn=new BufferedReader(new InputStreamReader(con.getInputStream()));
             BufferedWriter bufw=new BufferedWriter(new FileWriter(new File("D:\360Downloads\mailaddress2.txt")));
             String str=null;
             String regex="[a-zA-Z0-9_]{6,12}@[a-zA-Z0-9]+(.[a-zA-Z]+)+";
    
             Pattern p=Pattern.compile(regex);
             System.out.println("start");
             while((str=bufIn.readLine())!=null) {
                Matcher m=p.matcher(str);
                while(m.find()){
                    String ss=m.group();
                    bufw.write(ss,0,ss.length());
                    bufw.newLine();
                    bufw.flush();
                }
             }
             System.out.println("end");
         }
    }

    获取网页内容,并将页面中的邮件地址存存放在指定的路径中,写入到txt文件里

  • 相关阅读:
    MOS
    1- Bluetooth开发
    1- Bluetooth
    MCU 51-10 Infrared Communication
    1- STM32 HAL库学习 GPIO配置点亮LED灯
    MCU 51-9 DS18B20 Temperature Sensor
    MCU 51-8 AD/DA
    C语言讲义——变量(variable)
    C语言讲义——注释
    C语言讲义——“编译、链接”
  • 原文地址:https://www.cnblogs.com/jiafuwei/p/6080996.html
Copyright © 2011-2022 走看看