Skip to content

Instantly share code, notes, and snippets.

@blahutka
Forked from terraboops/Gemfile
Created January 20, 2016 11:33
Show Gist options
  • Save blahutka/045917b9e84e16408d32 to your computer and use it in GitHub Desktop.
Save blahutka/045917b9e84e16408d32 to your computer and use it in GitHub Desktop.
Simple Mechanize Scraper

Instructions

  • Put both files into an empty directory
  • Open a shell prompt to the directory with the Gemfile and scraper.rb files.
  • Ensure you have bundler installed: gem install bundler
  • Install the dependencies: bundle install
  • Execute the scraper: ruby scarper.rb
source 'https://rubygems.org'
gem 'mechanize'
require 'mechanize'
require 'io/console'
agent = Mechanize.new
page = agent.get('https://github.com/login')
# GitHub's forms didn't have names, had to look up by their action
# Selects the first form whose action includes "/session" from the page's forms array
form = page.forms.find{|form| form.action.include?("/session")}
puts "Command Line GitHub login!"
puts "Login:"
form.login = gets.chomp
print "Password: "
form.password = STDIN.noecho(&:gets).chomp
page = agent.submit(form)
pp page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment