http://union.suning.com/aas/open/vistorAd.action?userId=124924&webSiteId=12164&adInfoId=6494&adBookId=48681&subUserEx=155412&vistURL=http://www.suning.com

抓取网页

            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("成功");

 

posted @ 2015-07-01 08:41  .netpjava  阅读(158)  评论(0编辑  收藏  举报