我正在try Select 其 node 包含名称以‘on’开头的属性的所有HTML node .
以下是我为XPath准备的内容:
//*[@*[starts-with(name(), 'on')]]
当我使用上面的XPath和html <div onclick="alert('test');"></div>
呼叫SelectNodes
时,我得到的结果是空的.
var document = new HtmlDocument();
document.LoadHtml("<div onclick=\"alert('test');\"></div>");
var nodes = document.DocumentNode.SelectNodes("//*[@*[starts-with(name(), 'on')]]");
我在两个XPath测试站点(https://www.freeformatter.com/xpath-tester.html#before-output和http://xpather.com/)上测试了XPath,它们都返回div node .XPath函数不能与HTML Agility Pack一起使用吗?我需要为HTML敏捷包做一些不同的事情吗?