示例#1
0
        private void Gather(object obj)
        {
            IdUrl  idurl = obj as IdUrl;
            int    i     = idurl.id;
            string url   = idurl.url;

            StreamReader sr;

            try
            {
                HttpWebRequest  webRequest  = (HttpWebRequest)WebRequest.Create("http://www.baidu.com/s?wd=" + url);
                HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
                //Stream srtStream = webResponse.GetResponseStream();
                sr = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));
            }
            catch
            {
                MessageBox.Show("对不起!网络没有连接。");
                return;
            }
            finally
            {
            }
            String totalLines = sr.ReadToEnd();
            //匹配标题
            Regex reg = new Regex("没有找到该URL。您可以直接访问");
            Match mat = reg.Match(totalLines);

            if (!mat.Success)
            {
                MatchCollection mc_title = Common.MatchURLs(totalLines, "<h3 class=\"t\">", "</h3>");
                MatchCollection mc_url   = Common.MatchURLs(totalLines, "<span class=\"g\">", "</span>");
                MatchCollection mc_time  = null;
                if (mc_url.Count != 0)
                {
                    mc_time = Common.MatchURLs(mc_url[0].Value, "&nbsp;", "&nbsp;");
                }
                if (mc_title.Count != 0 && mc_time.Count != 0 && Common.compareString(Common.StripHT(mc_url[0].Value), url))
                {
                    j++;
                    //dt1.Rows[i][1] = Common.StripHT(mc_title[0].Value);
                    dt1.Rows[i][3] = true;
                    dt1.Rows[i][5] = mc_time[0].Value;
                    //dt1.AcceptChanges();
                }
            }


            y++;
            //实时更新界面元素
            Thread trd = new Thread(new ThreadStart(this.ThreadTask));

            trd.IsBackground = true;
            trd.Start();

            Thread.Sleep(Common.RandomInt(500, 700));
        }
 public void Get(IdUrl url) { }