From: Peter Szinek Date: 2006-11-20T01:46:22+09:00 Subject: Re: Ruby screen scraping Chris Gallagher wrote: > thanks guys I'll look into both of them. > > Another question I would have is how would i then get this scraped info > to insert into a mysql database called say "build" and a table called > "results". > > For now if you could base answers on the following htree code? > > require 'open-uri' > require 'htree' > require 'rexml/document' > > url = "http://www.google.com/search?q=ruby" > open(url) { > |page| page_content = page.read() > doc = HTree(page_content).to_rexml > doc.root.each_element('//a[@class="l"]') { > |elem| puts elem.attribute('href').value } > } Something along the lines of require "mysql" dbh = Mysql.real_connect("localhost", "chris", "", "build") dbh.query(" INSERT INTO results VALUES (whatever) Cheers, Peter __ http://www.rubyrailways.com