Is there a Sizzle/jQuery selectors implementation in C#? [closed]
Asked Answered
B

1

13

I need to be able to simply specify elements from html in my C# application. I would just use Linq to Sql but this needs to be configurable/serializable to a string. I could of course use XPath but something like Sizzle at this point is just so much more natural for most people.

Anyone know if a sizzle selectors implementation exists in .Net?

Braggadocio answered 11/9, 2011 at 17:3 Comment(1)
CsQuery seems to be very promising. I have not used it yet, just read about it -- after browsing through this question. Should not be closed.Midsection
S
19

Yepp, Fizzler. It's built upon HtmlAgilityPack and works very well, even though the authors says it's beta. We use it in production on a major project. Samples from the documentation:

// 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");
Sinusoid answered 11/9, 2011 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.