繁体   English   中英

从img标签获取src属性

[英]Getting src attribute from img tag

我正在使用HAP库来解析HTML: http : //html-agility-pack.net

我基本上只想从所有img标记中检索src值。

我尝试了几件事,但似乎无法做到!

从示例页面修改:

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
}

您是否尝试过这样的事情:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM