日期:2014-05-19  浏览次数:20869 次

如何得到一个页面中的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图片的地址
}
}

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