Java 抓取任意网址中的所有邮箱地址
## 代码
```java
public static void main(String[] args) throws IOException {
// 定义邮箱匹配正则
Pattern p = Pattern.compile("[0-9a-zA-Z_]+@[0-9a-zA-Z]+(\\.[a-zA-Z]+)+");
// 设置目标网页
URL url = new URL("https://baike.xsoftlab.net");
// 建立IO连接
URLConnection connection = url.openConnection();
// 读取网页内容
String line = null;
BufferedReader bf = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = bf.readLine()) != null) {
// 输出网页源代码
// System.out.println(line);
Matcher m = p.matcher(line);
// 打印正则匹配到的内容
while (m.find()) {
System.out.println(m.group());
}
}
// 关闭流
bf.close();
}
```
### 输出
```
service@xsoftlab.net
service@xsoftlab.net
```