怎么提取img中 src中的内容?

wenle 2008-07-02 01:25:07
例如:在如下的标记中,我要提取src中的内容http://192.168.1.72/WebAdmin/images/image.jpg
<IMG height=372 alt=aa src="http://192.168.1.72/WebAdmin/images/image.jpg" width=594 border=0>
...全文
298 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangwei155 2008-07-02
  • 打赏
  • 举报
回复
还是加个id属性来的方便
<IMG id="img1" height=372 alt=aa src="http://192.168.1.72/WebAdmin/images/image.jpg" width=594 border=0>

var url = document.getElementById("img1").value;
insus 2008-07-02
  • 打赏
  • 举报
回复
Insus.NET试练了一下,不防参考参考,是否合你的要求:



string str="<IMG height=\"372\" alt=\"aa\" src=\"http://192.168.1.72/WebAdmin/images/image.jpg\" width=\"594\" border=\"0\" />";


XmlDocument xDoc = new XmlDocument();
xDoc.Load(new System.IO.MemoryStream(System.Text.Encoding.GetEncoding ("UTF-8").GetBytes (str)));
XmlNodeList xNode = xDoc.SelectNodes("//IMG");
{
for (int i = 0; i < xNode.Count; i++)
{
Response.Write ( xNode[i].Attributes["src"].Value);
}
}
家鸣 2008-07-02
  • 打赏
  • 举报
回复


Match m= Regex.Match("<IMG height=372 alt=aa src=\"http://192.168.1.72/WebAdmin/images/image.jpg\" width=594 border=0>","(?<=<img.+?src=\")[^\"]+(?=\")",RegexOptions.IgnoreCase);
string str=m.Value;
tt5201 2008-07-02
  • 打赏
  • 举报
回复

protected void Page_Load(object sender, EventArgs e)
{
string str = "<IMG height=372 alt=aa src=\"http://192.168.1.72/WebAdmin/images/image.jpg\" width=594 border=0>";
string[] temp;

string test = "src=\"(?<qs>[\\s\\S]*?)\"([\\s\\S]*?)>";
Regex reg = new Regex(test);
temp = new string[reg.Matches(str).Count];


int i = 0;
foreach (Match match in reg.Matches(str.Replace("\r", "").Replace("\n", "").Replace("\r\n", "")))
{
if (match.Success)
{
temp[i] = match.Groups["qs"].Value.ToString();
i++;

}

}
}
syc958 2008-07-02
  • 打赏
  • 举报
回复
这个很简单呀!

<script language="javascript">

function dd()
{

var a=document.body.innerHTML;
var b=/src=\"([^\"]*?)\"/gi;
var s=a.match(b);

for(var i= 0;i<s.length;i++)
{
alert(s[i]);
alert(RegExp.$1)
}
}


</script>
<p> <span style="font-size: 14pt"> <img height="175" width="257" align="left" alt="" src="/wzyxy/uploads/image/PICT0188(1).JPG" height="175" width="257" />6 </span><input type="button" onclick="dd()"/>
wdgphc 2008-07-02
  • 打赏
  • 举报
回复
http://www.cnblogs.com/hobe/archive/2007/03/14/674292.html
ljqingas 2008-07-02
  • 打赏
  • 举报
回复

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧