首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么得到一个页面中的jpg图象

2012-01-22 
如何得到一个页面中的jpg图象?如题~我想得到一个页面中所有的JPG图象,应该如何操作??知道的大哥,告知小弟

如何得到一个页面中的jpg图象?
如题~
我想得到一个页面中所有的JPG图象,应该如何操作??知道的大哥,告知小弟一下!

[解决办法]
HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create( "http://www.xxx.com ");
wr.ContentType = "application/x-www-form-urlencoded ";
wr.Accept = "*/* ";
wr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322) ";
HttpWebResponse myHttpWebResponse = (HttpWebResponse)wr.GetResponse();
StreamReader oStream = new StreamReader(myHttpWebResponse.GetResponseStream(),System.Text.Encoding.Default);
string res = oStream.ReadToEnd();

MatchCollection Matches = Regex.Matches(res, " <img\\s*src=(\\S*)\\.jpe?g ",RegexOptions.ExplicitCapture|RegexOptions.IgnoreCase);
if(!Matches.Count.Equals(0))
{
foreach(Match NextMatch in Matches)
{
//NextMatch.Value就是一个jpg图片的地址
}
}

仓促之间写的,楼主权当参考
[解决办法]
用正则表达式分析图片链接是速度最快的方法

热点排行