From: James Britt Date: 2005-06-17T23:04:21+09:00 Subject: Re: Watir , REXML, Espen Falkevik wrote: > Hi > I looked at this project, but I can't seem to find the > examples/code that can help me... > Can anyone tell me how to fetch the HTML code and > convert it into a REXML document? The project is Mechanize (though it is listed on the same main page as the Wee project; really should get its own page, Michael!). You can install Mechanize using rubygems. This example logs into rubyforge.org, using values passed at the command line: require 'mechanize' agent = WWW::Mechanize.new {|a| a.log = Logger.new(STDERR) } page = agent.get('http://rubyforge.org/') link = page.links.find {|l| l.node.text =~ /Log In/ } page = agent.click(link) form = page.forms[1] form.fields.find {|f| f.name == 'form_loginname'}.value = ARGV[0] form.fields.find {|f| f.name == 'form_pw'}.value = ARGV[1] page = agent.submit(form, form.buttons.first) puts page.root.class img_alt = REXML::XPath.first( page.root, "//img" ).attributes[ 'alt' ] p img_alt The 'root' method of the Page instance returns a REXML Document. James Britt -- http://www.ruby-doc.org - The Ruby Documentation Site http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML http://www.rubystuff.com - The Ruby Store for Ruby Stuff http://www.jamesbritt.com - Playing with Better Toys