var imgarr = document.images
或者是这个,然后遍历得到src就可以了
第一种方法,就是用正则表达式来匹配所有的图片。
第二种,通过js 中的document.getElemetsByTag("img"),再通过遍历来获取
using System.Text.RegularExpressions;
GetImgTag(“html代码”)
public string[] GetImgTag(string strHTML)
{
Regex regObj = new Regex("<img.+?>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
string[] strAry = new string[regObj.Matches(strHTML).Count];
int i = 0;
foreach (Match matchItem in regObj.Matches(strHTML))
{
string matchvalue=GetImgUrl(matchItem.Value);
if(matchvalue!=null) { strAry[i] = matchvalue;
i++;}
}
return strAry;
}
public string GetImgUrl(string imgTagStr)
{
Regex regObj = new Regex(@"http://.+?.(gif|bmp|jpg|jpeg)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
foreach (Match matchItem in regObj.Matches(imgTagStr))
{
Uri u = new Uri(matchItem.Value);
if (u.Host == HttpContext.Current.Request.Url.Host) return null;
return matchItem.Value;
}
return null;
}
document.getElemetByID("imgID").src