java在网页上面抓取邮件地址的方法
作者:shichen2014 时间:2023-10-01 19:18:21
本文实例讲述了java在网页上面抓取邮件地址的方法。分享给大家供大家参考。具体实现方法如下:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class h1
{
public static String getWebCon(String domain)
{
System.out.println("开始抓取邮件地址..("+domain+")");
StringBuffer sb=new StringBuffer();
try
{
java.net.URL url=new java.net.URL(domain);
BufferedReader in=new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while((line=in.readLine())!=null)
{
parse(line);
}
in.close();
}
catch(Exception e)
{
sb.append(e.toString());
System.err.println(e);
}
return sb.toString();
}
public static void main(String[] args)
{
String s;
s=h1.getWebCon("http://post.baidu.com/f?kz=34942387"); //这是要抓取的网页,自己可以试下.
//System.out.println(s);
}
private static void parse(String line)
{
Pattern p=Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+");//邮箱的正则表达式
Matcher m=p.matcher(line);
while(m.find())
{
System.out.println(m.group());
}
}
}
希望本文所述对大家的Java程序设计有所帮助。
标签:java,网页,抓取
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
深入分析Java内存区域的使用详解
2023-09-25 23:21:29
Android scheme 跳转的设计与实现详解
2021-07-29 03:42:52
Android使用友盟集成QQ、微信、微博等第三方分享与登录方法详解
2022-03-07 01:46:30
![](https://img.aspxhome.com/file/2023/6/137966_0s.png)
解决SpringMVC拦截器path路径的坑
2023-03-24 17:02:01
简单通用JDBC辅助类封装(实例)
2021-10-14 23:09:28
面试中遇到的java逃逸分析问题
2021-12-08 11:58:28
详解Java如何实现在PDF中插入,替换或删除图像
2022-04-07 22:40:36
![](https://img.aspxhome.com/file/2023/4/80864_0s.jpg)
Android Walker登录记住密码页面功能实现
2023-12-16 05:45:03
![](https://img.aspxhome.com/file/2023/6/137436_0s.jpg)
springboot如何统一设置时区
2022-01-26 18:16:39
![](https://img.aspxhome.com/file/2023/9/63659_0s.png)
关于Jedis的用法以及Jedis使用Redis事务
2023-06-28 07:22:56
![](https://img.aspxhome.com/file/2023/6/113476_0s.jpg)
一篇文章带你入门Java数据类型
2022-06-10 09:25:44
![](https://img.aspxhome.com/file/2023/8/62338_0s.jpg)
SpringBoot2之PUT请求接收不了参数的解决方案
2023-08-23 01:32:07
![](https://img.aspxhome.com/file/2023/2/58202_0s.png)
使用springboot logback动态获取application的配置项
2023-09-03 21:21:41
Spring AOP AspectJ使用及配置过程解析
2023-09-29 00:17:45
Java的锁机制:synchronized和CAS详解
2023-03-18 16:04:00
![](https://img.aspxhome.com/file/2023/9/101929_0s.png)
java实现两个对象之间传值及简单的封装
2022-03-11 13:53:18
![](https://img.aspxhome.com/file/2023/3/132083_0s.jpg)
Spring框架七大模块简单介绍
2023-03-10 10:25:23
![](https://img.aspxhome.com/file/2023/1/64901_0s.jpg)
Java线程池并发执行多个任务方式
2023-08-14 16:26:03
![](https://img.aspxhome.com/file/2023/4/80274_0s.jpg)
Android自定义带圆角的ImageView
2022-12-12 23:48:07
SpringBoot自动配置原理分析
2022-03-02 17:42:51
![](https://img.aspxhome.com/file/2023/8/62058_0s.webp)