我需要能够在我的 C# 应用程序中简单地指定来自 html 的元素。我只会使用 Linq to Sql 但这需要可配置/可序列化为字符串。我当然可以使用 XPath,但此时像 Sizzle 这样的东西对大多数人来说更加自然。
任何人都知道.Net 中是否存在嘶嘶声选择器实现?
我需要能够在我的 C# 应用程序中简单地指定来自 html 的元素。我只会使用 Linq to Sql 但这需要可配置/可序列化为字符串。我当然可以使用 XPath,但此时像 Sizzle 这样的东西对大多数人来说更加自然。
任何人都知道.Net 中是否存在嘶嘶声选择器实现?
是的,菲兹勒。它建立在 HtmlAgilityPack 之上并且运行良好,尽管作者说它是测试版。我们在一个主要项目的生产中使用它。文档中的示例:
// Load the document using HTMLAgilityPack as normal
var html = new HtmlDocument();
html.LoadHtml(@"
<html>
<head></head>
<body>
<div>
<p class='content'>Fizzler</p>
<p>CSS Selector Engine</p></div>
</body>
</html>");
// Fizzler for HtmlAgilityPack is implemented as the
// QuerySelectorAll extension method on HtmlNode
var document = htmlDocument.DocumentNode;
// yields: [<p class="content">Fizzler</p>]
document.QuerySelectorAll(".content");
// yields: [<p class="content">Fizzler</p>,<p>CSS Selector Engine</p>]
document.QuerySelectorAll("p");
// yields empty sequence
document.QuerySelectorAll("body>p");
// yields [<p class="content">Fizzler</p>,<p>CSS Selector Engine</p>]
document.QuerySelectorAll("body p");
// yields [<p class="content">Fizzler</p>]
document.QuerySelectorAll("p:first-child");