把动态网页静态化
private bool CreateList(string url, string fna)
{
bool ok;
//准备生成
string strHtml;
StreamReader sr = null; //用来读取流
StreamWriter sw = null; //用来写文件
Encoding code = Encoding.GetEncoding("utf-8"); //定义编码
//构造web请求,发送请求,获取响应
WebRequest HttpWebRequest = null;
WebResponse HttpWebResponse = null;
HttpWebRequest = WebRequest.Create(url);
HttpWebResponse = HttpWebRequest.GetResponse();
//获得流
sr = new StreamReader(HttpWebResponse.GetResponseStream(), code);
strHtml = sr.ReadToEnd();
//写入文件
sw = new StreamWriter(fna, false, code);
sw.Write(strHtml);
sw.Flush();
ok = true;
sw.Close();
return ok;
}
评论