C# 如何使用IHTMLDocument2获取具有特定属性的元素?

C# 如何使用IHTMLDocument2获取具有特定属性的元素?,c#,html,asp.net,asp.net-mvc,C#,Html,Asp.net,Asp.net Mvc,我正在使用C#(控制台应用程序)使用WebClient类从URL中下拉DOM,并使用IHTMLDocument2接口解析HTML 目前,我可以通过以下方式访问DOM中的所有img元素: //string htmlContent is defined somewhere above as stream returned from WebClient response IHTMLDocument2 htmlDocument = (IHTMLDocument2)new mshtml.HTMLDocu

我正在使用C#(控制台应用程序)使用
WebClient
类从URL中下拉DOM,并使用
IHTMLDocument2
接口解析HTML

目前,我可以通过以下方式访问DOM中的所有img元素:

//string htmlContent is defined somewhere above as stream returned from WebClient response

IHTMLDocument2 htmlDocument = (IHTMLDocument2)new mshtml.HTMLDocument();

htmlDocument.write(htmlContent);

IHTMLElementCollection myImages = htmlDocument.images;

有人知道我可以使用
IHTMLDocument2
(或其他)接口仅获取具有特定类的img元素的方法吗?任何具有特定类/属性的元素如何?

您可能会查找该类/属性在该相关对象上是否可用。旁注:用HTMLAgilityPack解析HTML会更安全,你会发现有更多的示例可以这样做。@AlexeiLevenkov谢谢你的提示。我将研究querySelector和HTMLAgilityPack。我希望在不引入额外库的情况下也能做到这一点,所以我将首先看看我能用前者实现什么