首页 新闻 会员 周边

怎么查找html代码中的图片地址

0
悬赏园豆:20 [已关闭问题]

<img.+?src\s*=.*(?<gif>.+?gif).+?>

 

 

hsj的主页 hsj | 初学一级 | 园豆:90
提问于:2009-05-15 17:42
< >
分享
其他回答(3)
0

var imgarr = document.images

或者是这个,然后遍历得到src就可以了

kaixin110 | 园豆:16 (初学一级) | 2009-05-15 18:16
0

第一种方法,就是用正则表达式来匹配所有的图片。

第二种,通过js 中的document.getElemetsByTag("img"),再通过遍历来获取

李.net | 园豆:730 (小虾三级) | 2009-05-15 22:49
0

 

     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;

       }

 

黑白之间 | 园豆:859 (小虾三级) | 2009-05-16 21:25
0

document.getElemetByID("imgID").src

sl2008 | 园豆:407 (菜鸟二级) | 2009-05-18 10:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册