首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

.net抓取百度造成。百度局域网错误访问

2013-12-13 
.net抓取百度造成。百度局域网异常访问直接贴代码。public static HttpWebResponse CreateGetHttpResponse(s

.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)
            {
                foreach (var key in keys)
                {
                    int num = 10;//搜索条数
                    string url = "http://www.baidu.com/s?wd=" + item.QYName + " " + key + "&rn=" + num + "";//根据企业名称+关键字搜索
                    Uri urls = new Uri(url);
                    string html = html = search(url, "gb2312");//gb2312
                    //string html = HttpWebResponseUtility.GetHttpSourceValue(url);
                    //string html = GetHTMLTCP(url);
                   // string html2 = GetHTML(url,"gb2312");
                    //string html = HttpWebResponseUtility.GetHtmlSource2("http://www.baidu.com");
                    string html = HttpWebResponseUtility.GetHtml(url, Encoding.UTF8);
                    //this.webBrowser1.Url = urls;


                    BaiduSearch baidu = new BaiduSearch();
                    if (!string.IsNullOrEmpty(html))
                    {
                        int count = baidu.GetSearchCount(html);//搜索条数
                        if (count > 0)
                        {
                            List<Keyword> keywords = baidu.GetKeywords(html, item.QYID, item.QYName, "");
                            //dataGridView1.DataSource = keywords;
                        }

                        if (count == 0)
                        {
                            var time = DateTime.Now;
                        }

                    }
                }
            }

            //企业法人
            foreach (var item in qys)
            {
                foreach (var key in keys)
                {
                    if (!string.IsNullOrEmpty(item.FName))
                    {
                        int num = 10;//搜索条数
                        string url = "http://www.baidu.com/s?wd=" + item.FName + " " + key + "&rn=" + num + "";//根据企业法人名字+关键字搜索
                        Uri urls = new Uri(url);
                        string html = search(url, "gb2312");//UTF-8
                        //this.webBrowser1.Url = urls;
                        BaiduSearch baidu = new BaiduSearch();
                        if (!string.IsNullOrEmpty(html))
                        {
                            int count = baidu.GetSearchCount(html);//搜索条数
                            if (count > 0)
                            {
                                List<Keyword> keywords = baidu.GetKeywords(html, item.QYID, item.QYName, item.FName);


                                //dataGridView1.DataSource = keywords;
                            }

                        }
                    }
                }
            }
        }



.net抓取百度造成。百度局域网错误访问
httprequsert.proy 启用代理  免费代理自己可以百度一下
[解决办法]

我擦 你会引用不

string html=GetHtml("http://www.baidu.com"+关键词,"188.44.44.11",8080);

就这样

热点排行