软件编程
位置:首页>> 软件编程>> java编程>> Java 从互联网上爬邮箱代码示例

Java 从互联网上爬邮箱代码示例

作者:luoxn28  发布时间:2022-02-27 16:40:57 

标签:java,爬虫

网页爬虫:其实就是一个程序用于在互联网中获取符合指定规则的数据。


package day05;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SpiderDemo {
 public static void main(String[] args) throws IOException {
   List<String> list = getMailByWeb();
   for (String mail : list) {
     System.out.println(mail);
   }
 }
 public static List<String> getMailByWeb() throws IOException {
   URL url = new URL("http://www.itheima.com/aboutt/1376.html");
   BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
   String regex = "\\w+@\\w+(\\.\\w+)+";
   Pattern p = Pattern.compile(regex);
   List<String> list = new ArrayList<String>();
   String line = null;
   while ((line = input.readLine()) != null) {
     Matcher m = p.matcher(line);
     while (m.find()) {
       list.add(m.group());
     }
   }
   return list;
 }
}

总结

 Jsoup解析html方法,通常被人称之为爬虫技术。(个人认为可能是返回的数据,只有一小部分是我们需要的,造成了数据的冗余,和网络延迟)。

来源:http://blog.csdn.net/u012796139/article/details/50603961

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com