如何从C#中的HTML文件中提取图像URL [英] How to extract image urls from HTML File in C#
本文介绍了如何从C#中的HTML文件中提取图像URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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));
}
Can anyone help me by explaining how to extract image urls from HTML File in C#
解决方案
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));
}
这篇关于如何从C#中的HTML文件中提取图像URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文