从img标签获取src属性 [英] Getting src attribute from img tag
本文介绍了从img标签获取src属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用HAP库来解析HTML: http://html-agility-pack.net
I'm using the HAP library to parse HTML: http://html-agility-pack.net
我基本上只想从所有img
标记中检索src
值.
I basically just want to retrieve the src
value from all the img
tags.
我已经尝试了好几件事,但是我似乎做不到!
I've tried several thing but I can't seem to do it!
推荐答案
在示例页面中进行了修改:
Modified from the examples page:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm"); //or whatever HTML file you have
HtmlNodeCollection imgs = doc.DocumentNode.SelectNodes("//img[@src]");
if (imgs == null)
return;
foreach (HtmlNode img in imgs)
{
if (img.Attributes["src"] == null)
continue;
HtmlAttribute src = img.Attributes["src"];
//Do something with src.Value
}
这篇关于从img标签获取src属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文