views:

461

answers:

2

What HTML parser for Ruby will I find easiest to use if I'm already familiar / in love with jQuery?

Such a parser would have jQuery's overall philosophy -- "grab some HTML elements (using CSS selectors) and do things with them" -- and in addition have equivalents for all of jQuery's DOM manipulation functionality (prepend(), after(), etc).

Obviously it wouldn't make sense for a server-side parser to support jQuery event, effect, or AJAX functionality.

Edit: Hpricot does this pretty well (e.g., doc.search('#menu').inner_html) -- is there anything with a better API? (When I Google "nokogiri v. hpricot" all I get are speed comparisons. I don't care about speed! I just want a library that's fun / easy to use!)

A: 

Wouldn't this be more than achievable using nothing other than Ruby's own string manipulation and some very light regex (maybe? I haven't touched ruby in a while).

Sneakyness
Nothing but the most basic manipulation of HTML should *ever* be done using string manipulation and regex.
Pesto
Not in a million years.
Chuck
+3  A: 

You'd probably be most at home with Hpricot. Heck, it even says it right there on the front page:

Hpricot is a very flexible HTML parser, based on Tanaka Akira’s HTree and John Resig’s jQuery, but with the scanner recoded in C. I’ve borrowed (what I believe to be) the best ideas from these wares to make Hpricot heaps of fun to use.

Pesto