HTML Tools for Ruby

ruby-htmltools consists of tools for parsing and manipulating HTML documents in Ruby. For example:

irb(main):001:0>        require 'html/tree'
irb(main):002:0> p =, false)
irb(main):003:0> p.feed('<html><head></head><body attrib1="xxx"><p>stuff</p></body></html>')
irb(main):004:0> p.html.to_s
=> "<html>"
irb(main):005:0> p.html.children.size
=> 2
irb(main):006:0> p.html.children[0].to_s
=> "<head>"
irb(main):007:0> p.html.children[1].to_s
=> "<body attrib1=\"xxx\">"
irb(main):008:0> p.html.children[1].attribute("attrib1")
=> "xxx"


The installation on Ruby Forge contains everything you need for Ruby 1.8

  1. Download latest tarbar from RubyForge project page
  2. Install using the setup.rb script:
  3. Require 'html/tree' in your Ruby script