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;
}
}
根据前面讲解的生成方法,需要访问动态页面戴上 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;
}
}
相关文章推荐
- Asp.net 静态页面生成(3)----动态页生成之 生成爬虫
- Asp.net 静态页面生成(3)----动态页生成之 生成爬虫
- ASP.NET生成静态页面实现方法
- ASP.NET生成静态页面的方法
- ASP.NET生成静态页面实现方法
- ASP.NET生成静态页面
- 用ASP.NET,C#实现生成静态页面
- Asp.net生成静态页面原理
- asp.net 不用模板生成静态页面
- ASP.NET生成静态页面的方法
- Asp.net生成静态页面最简单方法(源码)
- asp.net生成静态页面原理
- ASP.NET生成静态页面(页面输出)
- asp.net生成静态页面原理
- asp.net生成静态页面
- asp.net生成静态页面原理
- ASP.NET动态生成静态页面(C#)
- ASP.NET生成静态页面实现方法
- ASP.NET生成静态页面实现方法
- ASP.NET生成静态页面的方法