網頁爬蟲:其實就是一個程序用于在互聯網中獲取符合指定規則的數據。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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方法,通常被人稱之為爬蟲技術。(個人認為可能是返回的數據,只有一小部分是我們需要的,造成了數據的冗余,和網絡延遲)。
以上就是本文關于Java 從互聯網上爬郵箱代碼示例的全部內容,希望對大家有所幫助。有什么問題可以隨時留言,小編會及時回復大家。
原文鏈接:http://blog.csdn.net/u012796139/article/details/50603961