问题
Can anyone help me by explaining how to extract image urls from HTML File in C#
回答1:
The HTML Agility Pack can do this - just use a query like //img and access the src - like so:
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));
}
回答2:
You have to parse the HTML and check the img tag use the following link it includes C# library for parsing HTML tags i faced your problem b4 and i used this library and working well with me Parsing HTML tags
来源:https://stackoverflow.com/questions/790559/how-to-extract-image-urls-from-html-file-in-c-sharp