您的位置:首页 > 编程语言 > ASP

Asp.net 静态页面生成(3)----动态页生成之 生成爬虫

2014-11-16 10:49 351 查看
http://www.cnblogs.com/michael555cdj/archive/2008/03/23/1118819.html

根据前面讲解的生成方法,需要访问动态页面戴上 Create=true 参数就可以生成了。但是一个一个页面的访问是不是有点累啊

那我们就可以在生成管理器里面写个爬虫去爬遍每一个页面就可以达到生成的目的了。

由于采用http访问生成,爬虫可以在部署在任何位置,实例代码如下


public class Creater


{


public Creater(string serverName)


{


this._ServerName = serverName;


}


private string _ServerName;


public string ServerName


{


get


{


return _ServerName;


}


}


public int CreateArticlePage()


{


string sqlStr = "SELECT ArticelId FROM Article";


DataSet ds = DataBase.ExecuteDataset(sqlStr);


System.Collections.Generic.List<string> urls = new System.Collections.Generic.List<string>();


if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)


{


for (int i = 0; i < ds.Tables[0].Rows.Count; i++)


{


urls.Add("http://" + ServerName + "/Article/Show.aspx?ArticleId=" + ds.Tables[0].Rows[i].ToString());


}


}


return CreateHtml(urls);


}


private int CreateHtml(System.Collections.Generic.List<string> urls)


{


int result = 0;


System.Net.WebClient client = new System.Net.WebClient();


for (int i = 0; i < urls.Count; i++)


{


System.IO.Stream stream = client.OpenRead(urls[i]);


System.IO.StreamReader sr = new System.IO.StreamReader(stream);


result += int.Parse(sr.ReadToEnd());


}


return result;


}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: