全速加载中

抓取网页中图片的方法

代码示例:

 WebClient wc = new WebClient();
            byte[] bytes = new byte[1255];
            bytes = wc.DownloadData("http://www.cnblogs.com/");//要抓取的网址
            string srt = Encoding.UTF8.GetString(bytes);//将byte类型的数据转换成string类型
            //</?(a|A)( .*?>|>(.*)
            string getImg = "<img(.*)src=\"(.*).gif\"(.*)/>";//要匹配的正则表达式
            Match match = Regex.Match(srt, getImg);
          
            Response.Write(match.Groups[2].Value.ToString()+".gif");

 

posted @ 2013-05-11 15:51  许鸿飞  阅读(390)  评论(0编辑  收藏  举报