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

c#数据采集注意事项

2013-12-18 14:57 176 查看
HttpWebRequest httpWeb = (HttpWebRequest)HttpWebRequest.Create("http://ypk.39.net/yaopin/zc/liqi/7c872.html");

                httpWeb.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";

                httpWeb.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";

                httpWeb.ContentType = "application/x-www-form-urlencoded";

                httpWeb.Method = "get";

                httpWeb.CookieContainer = new CookieContainer();

                httpWeb.KeepAlive = false;

                HttpWebResponse httpRes = httpWeb.GetResponse() as HttpWebResponse;

                Stream resStream = httpRes.GetResponseStream();

                StreamReader sr = new StreamReader(resStream, System.Text.Encoding.GetEncoding("gb2312"));

                string strCode = sr.ReadToEnd();

                resStream.Close();

                FileHelper.WriteFile("D://a.html", strCode);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: