I was trying to learn the usage of ruby Mechanize gem from which I was able to fill the form and login to the website. But I was not able to extract the after logging in. Basically that website is displaying data only after logged in else it shows some default strings. eg: 'View website' instead of www.example.com
I tried writing this code:
#code to login
require 'mechanize'
require 'logger'
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'zlib'
mechanize = Mechanize.new
login = mechanize.get('website login page')
form = login.forms.first
form['student_email'] = 'email@gmail.com'
form['student_password'] = 'password'
result = form.submit
puts result.code
puts "logged in"
#code to extract
url = 'data_path_url'
doc = Nokogiri::HTML(open(url))
paths = doc.css('.college_name a') #capturing the link to extract.
paths.each do |path|
path = path['href']
path = path.to_s
page = Nokogiri::HTML(open(path))
data = page.css('.font11.bold') #data to extract
puts data.text #data to display.
end
I was still getting the default strings which I have to get without logging in. I would be glad if someone could help me with this code to stay in the session until the extraction completes.