如何从C#中的HTML文件中提取图像URL [英] How to extract image urls from HTML File in C#

查看:289
本文介绍了如何从C#中的HTML文件中提取图像URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过解释如何从C#中的HTML文件中提取图像URL来帮助我解决方案 HTML Agility Pack 可以做到这一点 - 只需使用像/ 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));
}


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆