根据一个Url 地址获取该网页的title 和 图标信息,我不想获取整个网页源码  然后再正则匹配
 WebClient myWebClient = new WebClient();
byte[] myDataBuffer = myWebClient.DownloadData(url);
这样会获取整个网页信息,效率明显慢了许多我只需要title、
有大神给点意见吗

解决方案 »

  1.   

    歪主意到是有,可以用Process通过 Process.MainWindowTitle 获取标题
      

  2.   

    我对比了下效率    DateTime start = DateTime.Now;
                string url = "http://www.ifeng.com";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "GET";
                req.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                Stream ReceiveStream = res.GetResponseStream();
                Encoding encode = System.Text.Encoding.UTF8;
                StreamReader sr = new StreamReader(ReceiveStream, encode);            string strResult = "";
                Char[] read = new Char[256];
                int count = sr.Read(read, 0, 256);
                while (count > 0)
                {
                    String str = new String(read, 0, count);
                    strResult += str;
                    count = sr.Read(read, 0, 256);
                    if (strResult.IndexOf("body") != -1)
                    {
                        break;
                    }
                }            TimeSpan span=DateTime.Now.Subtract(start);            DateTime start2 = DateTime.Now;
                WebClient myWebClient = new WebClient(); 
                byte[] myDataBuffer = myWebClient.DownloadData(url);
                string s = Encoding.UTF8.GetString(myDataBuffer);
                TimeSpan span2 = DateTime.Now.Subtract(start2);认为第一种方法可行
      

  3.   

    标题:网页<title>...</title>之间的内容
    图标:网站根路径下favico.ico文件用webclient或者httpwebrequest都可以。