`

java学习笔记:龙抓手之抓取网页中的邮件地址

    博客分类:
  • java
阅读更多

 



 

 

/*
正则表达式

  
[示例]:龙抓手之抓取网页中的邮件地址
*/
import java.net.*;
import java.io.*;
import java.util.regex.*;

class Demo
{
  public static void main(String[] args) throws Exception
  {
    getMails();
  }
  
  public static void getMails() throws Exception
  { 
    URL url=new URL("http://192.168.1.3/index.html");
    URLConnection conn=url.openConnection();
    BufferedReader bufrIn= new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line=null;
    String mailReg="\\w+@\\w+(\\.\\w+)+"; //模糊匹配
    
    Pattern pat=Pattern.compile(mailReg);
    while(true)
    {
      line=bufrIn.readLine();
      if(line!=null)
      {
        Matcher mat=pat.matcher(line);
        while(mat.find())
        {
          s.op(mat.group());
        }
      }
      else
      {
        break;
      }
    }
  }
}

 

  • 大小: 31.6 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics