java程序--从网页中提取电子邮箱地址
发布日期:2021-11-04 22:03:58 浏览次数:5 分类:技术文章

本文共 665 字,大约阅读时间需要 2 分钟。

先读取网页html代码,然后通过正则表达式提取点邮箱

public static void main(String[] args){

    URL url;

   try {

      url = new URL("http://home.focus.cn/msgview/607/1/9858619.html"); //网页url

     HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(); //连接

     urlConnection.connect();

     InputStream in = urlConnection.getInputStream();   //获取输入流

     byte[] data = new byte[4096];            

    while (in.read(data) > 0) {         //读取流文件

      String tempString = new String(data);

      String regex2 = "[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+";

       Matcher m=Pattern.compile(regex2).matcher(tempString);  

          while(m.find()) {

              System.out.println(m.group());

          }

      }

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

转载地址:https://blog.csdn.net/xiaochangwei789/article/details/7703125 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor
下一篇:网页验证码点击更换的简写代码

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月05日 02时27分59秒