- Put both files into an empty directory
- Open a shell prompt to the directory with the
Gemfile
andscraper.rb
files. - Ensure you have bundler installed:
gem install bundler
- Install the dependencies:
bundle install
- Execute the scraper:
ruby scarper.rb
Last active
May 27, 2020 21:02
-
-
Save terraboops/781f68add24819e207c4 to your computer and use it in GitHub Desktop.
Simple Mechanize Scraper
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
source 'https://rubygems.org' | |
gem 'mechanize' |
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
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