Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sigmike/204805 to your computer and use it in GitHub Desktop.
Save sigmike/204805 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'
require 'pp'
def url_for(path)
base = "http://example.com/"
base + path
end
h = WWW::Mechanize.new
h.get url_for("login.php") do |login|
form = login.forms.first
form.login = "my_login"
form.pass = "my_password"
page = h.submit(form, form.buttons.first)
suffix = Time.now.strftime("-%Y%m%d_%H%M%S.csv")
page = h.get url_for("tracking.php")
File.open("tracking#{suffix}", "w") do |f|
f.write page.body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment