Hpricot - HTML parser for Ruby

December 15, 2007 by pedro mota

Hpricot is a very interesting lib to parse HTML. I’ll post here the example, just to check on the beauty of it from time to time…\n\n\nrequire 'hpricot'\nrequire 'open-uri'\n# load the RedHanded home page\ndoc = Hpricot(open(\"http://redhanded.hobix.com/index.html\"))\n# change the CSS class on links\n(doc/\"span.entryPermalink\").set(\"class\", \"newLinks\")\n# remove the sidebar\n(doc/\"#sidebar\").remove\n# print the altered HTML\nputs doc\n\n\nThe lib is evolving, being added support for more XPath functions, etc.\n\nRedHanded’s blog from the same author, has another cool example. why rocks!

© 2018 | Follow on Twitter | pedro mg & Hugo