This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
%w(rubygems mechanize).each {|l| require l} | |
fail "Usage is: #{File.basename($0)} login password" if ARGV.length != 2 | |
login, password = *ARGV | |
agent = WWW::Mechanize.new | |
# grab the page with the login form in it | |
start_page = agent.get('https://www.blogger.com/start') | |
# grab the login form and fill in the credentials | |
login_form = start_page.form('login') | |
login_form.Email = login | |
login_form.Passwd = password | |
# login | |
agent.submit(login_form, login_form.buttons.first) | |
# now get the home page, follow links to the download, puts to stdout | |
home_page = agent.get('http://blogger.com/home') | |
settings_page = agent.click(home_page.link_with(:text => 'Settings')) | |
export_page = agent.click(settings_page.link_with(:text => 'Export blog')) | |
xml_page = agent.click(export_page.link_with(:text => 'Download Blog')) | |
puts xml_page.body |
I need to beef this up with some error handling obviously - but I think you'll find Mechanize to be pretty slick if you try it.