Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looking for C# Html parser with CSS selectors [closed]

Tags:

java

html

c#

right now I'm using HtmlAgilityPack.

but it very hard to select by Xpath.

In Java I know Jsoup. Is there any .net library that does the same?

parse Html and uses CSS style slectors to find elements.

like image 1000
Elad Benda Avatar asked Mar 03 '13 20:03

Elad Benda


1 Answers

Try Fizzler with HtmlAgilityPack.

Fizzler is:

A .NET library to select items from a node tree based on a CSS selector. The default implementation is based on HTMLAgilityPack and selects from HTML documents.

Example from project website:

// 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");
like image 97
Kamil Avatar answered Oct 07 '22 02:10

Kamil