如何从C#中的HTML文件中提取图像URL

9 .net html c# parsing extract

任何人都可以通过解释如何从C#中的HTML文件中提取图像URL来帮助我

Mar*_*ell 28

HTML敏捷性包可以做到这一点-只要使用像// IMG的查询和访问SRC -就像这样:

string html;
using (WebClient client = new WebClient()) {
    html = client.DownloadString("http://www.google.com");
}
HtmlDocument doc = new HtmlDocument();        
doc.LoadHtml(html);
foreach(HtmlNode img in doc.DocumentNode.SelectNodes("//img")) {
    Console.WriteLine(img.GetAttributeValue("src", null));
}
Run Code Online (Sandbox Code Playgroud)