抓取网页

            WebClient we = new WebClient();  //主要使用WebClient类
            byte[] myDataBuffer;
            myDataBuffer = we.DownloadData(textBox1.Text.Trim() );  //该方法返回的是 字节数组,所以需要定义一个byte[]
            string download = Encoding.UTF8.GetString(myDataBuffer);  //对下载的数据进行编码
            //通过查询源代码,获取某两个值之间的新闻内容
          
            int startIndex = download.IndexOf("<a class='toindex' href='/'>");
            //int endIndex = download.IndexOf("<a'>");
            MessageBox.Show(startIndex.ToString());
            string temp = download.Substring(startIndex,  startIndex + 30);  //截取新闻内容
            
            textBox2.Text  = temp;//显示所截取的新闻内容

            MessageBox.Show("成功");
原文地址:https://www.cnblogs.com/lushixiong/p/4612275.html