日期:2014-05-17  浏览次数:20490 次

.net抓取百度造成。百度局域网异常访问
直接贴代码。
  public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "GET";
            request.UserAgent = DefaultUserAgent;
            if (!string.IsNullOrEmpty(userAgent))
            {
                request.UserAgent = userAgent;
            }
            if (timeout.HasValue)
            {
                request.Timeout = timeout.Value;
            }
            if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }
            return request.GetResponse() as HttpWebResponse;
        }


  aTimer = new System.Timers.Timer(86400000);

            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

            aTimer.Interval = 3000;
            aTimer.Enabled = true;


  List<Qy> qys = Get_Coms();//所有法人
            List<Qy> qysss = qys.Distinct(c => c.QYID).ToList();//所有企业
            List<string> keys = Get_Keys();
            //企业
            foreach (var item in qysss)
            {