asp.net抓取页面内容+下载文件
程序员文章站
2022-05-03 09:23:19
#region 抓取页面的内容
public string GetHTML(string url)
{
ASCIIEncoding encoding...
#region 抓取页面的内容
public string GetHTML(string url)
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] postdata = encoding.GetBytes(posts);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
myRequest.ContentType = "text/html;";
myRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.2; rv:14.0) Gecko/20100101 Firefox/14.0.1";
myRequest.Host = "www.aizhan.com";
//myRequest.Headers.Add("Host", "www.aizhan.com");
myRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
myRequest.KeepAlive = true;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
return content;
}
public string GetHTML2(string url) {
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
byte[] btPageData = wc.DownloadData(url);
string strTargetHtml = Encoding.UTF8.GetString(btPageData);
wc.Dispose();
return strTargetHtml;
}
#endregion
public string GetHTML(string url)
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] postdata = encoding.GetBytes(posts);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
myRequest.ContentType = "text/html;";
myRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.2; rv:14.0) Gecko/20100101 Firefox/14.0.1";
myRequest.Host = "www.aizhan.com";
//myRequest.Headers.Add("Host", "www.aizhan.com");
myRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
myRequest.KeepAlive = true;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
return content;
}
public string GetHTML2(string url) {
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
byte[] btPageData = wc.DownloadData(url);
string strTargetHtml = Encoding.UTF8.GetString(btPageData);
wc.Dispose();
return strTargetHtml;
}
#endregion
上一篇: Python简单生成随机姓名的方法示例
推荐阅读
-
【ASP.NET】1.ASP.NET页面事件加载顺序以及Global.asax文件的使用
-
asp.net Web Services上传和下载文件(完整代码)第1/2页
-
Winform实现抓取web页面内容的方法
-
Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
-
Winform实现抓取web页面内容的方法
-
Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
-
HTML5 File接口在web页面上使用文件下载
-
ASP.NET Web Api 2实现多文件打包并下载文件的实例
-
ASP.NET(C#) Web Api通过文件流下载文件的实例
-
ASP.NET中iframe框架点击左边页面链接 右边显示链接页面内容