首先介绍每个类的功能:
DownloadPage.java的功能是下载此超链接的页面源代码.
FunctionUtils.java 的功能是提供不同的静态方法,包括:页面链接正则表达式匹配,获取URL链接的元素,判断是否创建文件,获取页面的Url并将其转换为规范的Url,截取网页网页源文件的目标内容。
HrefOfPage.java 的功能是获取页面源代码的超链接。
UrlDataHanding.java 的功能是整合各个给类,实现url到获取数据到数据处理类。
UrlQueue.java 的未访问Url队列。
VisitedUrlQueue.java 已访问过的URL队列。

下面介绍一下每个类的源代码:
DownloadPage.java 此类要用到HttpClient组件。 
1. package com.sreach.spider;
2.
3. import java.io.IOException;
4. import org.apache.http.HttpEntity;
5. import org.apache.http.HttpResponse;
6. import org.apache.http.client.ClientProtocolException;
7. import org.apache.http.client.HttpClient;
8. import org.apache.hods.HttpGet;
9. import org.apache.http.impl.client.DefaultHttpClient;
10. import org.apache.http.util.EntityUtils;
11.
12. public class DownloadPage
13. {
14.
15.     /**
16.       * 根据URL抓取网页内容
17.       * 
18.       * @param url
19.       * @return
20.       */
21.     public static String getContentFormUrl(String url)
22.     {
23.         /* 实例化一个HttpClient客户端 */
24.         HttpClient client = new DefaultHttpClient();
25.         HttpGet getHttp = new HttpGet(url);
26.
27.         String content = null;
28.
29.         HttpResponse response;
30.         try
31.         {
32.             /*获得信息载体*/
33.             response = ute(getHttp);
34.             HttpEntity entity = Entity();
35.
36.             VisitedUrlQueue.addElem(url);
37.
38.             if (entity != null)
39.             {
40.                 /* 转化为文本信息 */
41.                 content = String(entity);
42.
43.                 /* 判断是否符合下载网页源代码到本地的条件 */
44.                 if (FunctionUtils.isCreateFile(url)
45.                         && FunctionUtils.isHasGoalContent(content) != -1)
46.                 {
47.                     ateFile(FunctionUtils
48.                             .getGoalContent(content), url);
49.                 }
50.             }
51.
52.         } catch (ClientProtocolException e)
53.         {
54.             e.printStackTrace();
55.         } catch (IOException e)
56.         {
java手机游戏下载网站57.             e.printStackTrace();
58.         } finally
59.         {
60.             ConnectionManager().shutdown();
61.         }
62.          
63.         return content;
64.     }
65.
66. }
复制代码
FunctionUtils.java 此类的方法均为static方法
1. package com.sreach.spider;
2.
3. import java.io.BufferedWriter;
4. import java.io.File;
5. import java.io.FileOutputStream;
6. import java.io.IOException;
7. import java.io.OutputStreamWriter;
8. import Matcher;
9. import Pattern;
10.
11. public class FunctionUtils
12. {
13.
14.     /**
15.     * 匹配超链接的正则表达式
16.     */
17.     private static String pat = "www\\.oschina\\/code/explore/.*/\\w+\\.[a-zA-Z]+";
18.     private static Pattern pattern = Patternpile(pat);
19.
20.     private static BufferedWriter writer = null;
21.
22.     /**
23.     * 爬虫搜索深度
24.     */
25.     public static int depth = 0;
26.
27.     /**
28.     * "/"来分割URL,获得超链接的元素
29.     * 
30.     * @param url
31.     * @return
32.     */
33.     public static String[] divUrl(String url)
34.     {
35.         return url.split("/");
36.     }
37.
38.     /**
39.     * 判断是否创建文件
40.     * 
41.     * @param url
42.     * @return
43.     */
44.     public static boolean isCreateFile(String url)
45.     {
46.         Matcher matcher = pattern.matcher(url);
47.
48.         return matcher.matches();
49.     }
50.
51.     /**
52.     * 创建对应文件
53.     * 
54.     * @param content
55.     * @param urlPath
56.     */
57.     public static void createFile(String content, String urlPath)
58.     {
59.         /* 分割url */
60.         String[] elems = divUrl(urlPath);
61.         StringBuffer path = new StringBuffer();
62.
63.         File file = null;
64.         for (int i = 1; i < elems.length; i++)
65.         {
66.             if (i != elems.length - 1)
67.             {
68.
69.                 path.append(elems[i]);
70.                 path.append(File.separator);
71.                 file = new File("D:" + File.separator + String());
72.
73.             }
74.
75.             if (i == elems.length - 1)
76.             {
77.                 Pattern pattern = Patternpile("\\w+\\.[a-zA-Z]+");
78.                 Matcher matcher = pattern.matcher(elems[i]);
79.                 if ((matcher.matches()))
80.                 {
81.                     if (!ists())
82.                     {
83.                         file.mkdirs();
84.                     }
85.                     String[] fileName = elems[i].split("\\.");
86.                     file = new File("D:" + File.separator + String()
87.                             + File.separator + fileName[0] + ".txt");
88.                     try