Using a Ruby script to login to a website via https
Mechanize
Mechanize is ruby library which imititates the behaviour of a web browser. You can click links, fill out forms und submit them. It even has a history and remebers cookies. It seems your problem could be easily solved with the help of mechanize.
The following example is taken from http://docs.seattlerb.org/mechanize/EXAMPLES_rdoc.html:
require 'rubygems'
require 'mechanize'
a = Mechanize.new
a.get('http://rubyforge.org/') do |page|
# Click the login link
login_page = a.click(page.link_with(:text => /Log In/))
# Submit the login form
my_page = login_page.form_with(:action => '/account/login.php') do |f|
f.form_loginname = ARGV[0]
f.form_pw = ARGV[1]
end.click_button
my_page.links.each do |link|
text = link.text.strip
next unless text.length > 0
puts text
end
end
How do you scrape from a website which requires credentials (SSL)?
require 'httpclient'
require 'nokogiri'
client = HTTPClient.new
client.set_auth("http://domain.com", "username", "password")
doc = Nokogiri::HTML(c.get_content("http://example.com"))
Hey guys, sorry about the late response, I've been swamped with a few things. The code above worked for me. (after many tangos with mechanize and some of the other nokogiri-based gems). The some of the other gems such as openuri, mechanize, etc were resulting in errors such as MD5 Unknown hashing algorithm. Thanks for your time and help.
How to login on the site with JavaScript in Ruby on Rails?
This logged me in:
require "watir"
site_url = "http://vkontakte.ru"
ie = Watir::IE.new
ie.goto site_url
ie.text_field(:name, "email").set "disaster-ilya@mail.ru"
ie.text_field(:name, "pass").set "zothrf"
ie.link(:href, /quick_login/).click
Related Topics
What Is the Easiest Way I Can Create a 'Beep' Sound from a Ruby Program
How to Check What Is Queued in Activejob Using Rspec
Convert Datetime String to Utc in Rails
Disable Rvm or Use Ruby Which Was Installed Without Rvm
Rails Collection_Select VS. Select
How to Log the Entire Trace Back of a Ruby Exception Using the Default Rails Logger
How to Use Capybara in Pure Ruby (Without Rails)
Rails 5.2 Active Storage Add Custom Attributes
Postgresql Gem Pg Was Unable to Install
Renaming Uploaded Files with Carrierwave
How to Access a Ruby Module Method
Rails: How to Show User's "Last Seen At" Time
Better Way to Turn a Ruby Class into a Module Than Using Refinements