From: "Jesús Gabriel y Galán" Date: 2007-10-09T16:32:42+09:00 Subject: Re: Question about Mechanize and Google API On 10/9/07, mortee wrote: > Richard Conroy wrote: > > From my experience Mechanize is a bit low level, especially in this area. > > You are expected to write the code yourself to handle, redirects, > > authentication, > > SSL etc. > > > > You might want to try open-uri or Hpricot as well. But I think there is no > > right-sized solution - you will still need to do a bit of code writing yourself. > > Just for the record, last time I checked, Mechanize *did* use Hpricot to > parse pages. AFAIK, you can even provide Mechainze with your own page > parser class before fetching the stuff. Yes, Mechanize parses pages with Hpricot, and also allows you to use an Hpricot-like API on them for search: agent.get('http://rubyforge.org').search("//strong") The problem I was having with it is the fact that I didn't know how to specify arbitrary headers for my request, or make the Google authentication stuff to work. Working directly with net/https worked for me (code "inspired" by the Gdata gem :-): require 'net/http' require 'net/https' require 'uri' require 'hpricot' module Net class HTTPS < HTTP def initialize(address, port = nil) super(address, port) self.use_ssl = true end end end h = {"Email" => "xxxxx@gmail.com", "Passwd" => "xxxxx", "service" => "wise", "source" => "personal-test-1.0", "accountType" => "GOOGLE" } url = URI.parse('https://www.google.com/accounts/ClientLogin') response = Net::HTTPS.post_form(url, h) auth = "" response.body.each do |line| if line =~ /Auth=/ auth = line.split("=")[1].chomp end end headers = {"Authorization" => "GoogleLogin auth=#{auth}"} http = Net::HTTP.new("spreadsheets.google.com", 80) response, data = http.get("/feeds/spreadsheets/private/full", headers) document = Hpricot(data) document.search("//entry").each do |entry| p entry end This gives you a document with the list of private spreadsheets of the user. Then you can use Hpricot or whatever you want to parse the atom feed. Jesus.