如何在 C# 中从 HTML 文件中提取图像 url

发布于 2024-07-17 20:06:12 字数 44 浏览 3 评论 0原文

任何人都可以帮助我解释如何在 C# 中从 HTML 文件中提取图像 url

Can anyone help me by explaining how to extract image urls from HTML File in C#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌上芳菲 2024-07-24 20:06:12

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));
}

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));
}
韵柒 2024-07-24 20:06:12

您必须解析 HTML 并检查 img 标签,使用以下链接,它包含用于解析 HTML 标签的 C# 库,我遇到了您的问题 b4,我使用了这个库并与我合作良好 解析 HTML 标签

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文