How to extract image urls from HTML File in C#

旧巷老猫 提交于 2019-12-09 09:46:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!