代码示例:
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");