开发者

Getting src attribute from img tag

I'm using the HAP library to parse HTML: http://html-agility-pack.net

I basically just want to ret开发者_如何转开发rieve 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
}


Did you try something like this:

HtmlNodeCollection images = doc.DocumentNode.SelectNodes("//img[@src]");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜