Skip to content

Instantly share code, notes, and snippets.

@ywjno
Created May 9, 2012 06:47
Show Gist options
  • Save ywjno/2642513 to your computer and use it in GitHub Desktop.
Save ywjno/2642513 to your computer and use it in GitHub Desktop.
login github used mechanize
# encoding: utf-8
require 'rubygems'
require 'mechanize'
# Create a new mechanize object
agent = Mechanize.new
# set verify mode becaust the website used https
agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
# Load the github website
page = agent.get('http://github.com/login')
# Select the first form
form = page.forms[0]
# set your login and password in here
form.login = 'login'
form.password = 'password'
# Submit the form
page = form.submit form.buttons.first
# Print out the body
puts page.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment