HtmlAgilityPack HasAttribute?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: All I want to do is node.Attributes["class"].Value But if the node doesn't have the class attribute, it crashes. So, I have to check for its existence first, right? How do I do that? Attributes is not a dict (its a list that contains an internal dict??), and there's no HasAttribute method (just a HasAttributes which indicates if it has any attribute at all). What do I do? 回答1: Try this: String val; if(node.Attributes["class"] != null) { val = node.Attributes["class"].Value; } Or you might be able to add this public static class