Pregunta

I want to collect manufacturers and their medicine details from http://www.mims.com/India/Browse/Alphabet/All?cat=Company&tab=company.

Mechanize gem is used to extract content from html page with help of ryan Tutorial

I can login successfully but couldn't reach desination page http://www.mims.com/India/Browse/Alphabet/All?cat=Company&tab=company.

I have tried so far

require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'mechanize'
agent = Mechanize.new
agent.user_agent = 'Individueller User-Agent'
agent.user_agent_alias = 'Linux Mozilla'

agent.get("https://sso.mims.com/Account/SignIn") do |page|
  #login_page = a.click(page.link_with(:text => /Login/))
  # Submit the login form
  login_page = page.form_with(:action => '/') do |f|
    f.SignInEmailAddress = 'username of mims'
    f.SignInPassword = 'secret'
  end.click_button

  url = 'http://www.mims.com/India/Browse/Alphabet/A?cat=drug'
  page = agent.get url # here checking authentication if success then redirecting to destination
  p page
end

Note: I have shared dummy login credential for your testing

After clicks on 'CompaniesBrowse Company Directory' link, page redirecting with flash message "you are redirecting...", Mechanize gem caches this page.

Question:

1) How to get the original page(after redirection).

¿Fue útil?

Solución

I found problem cases that MIMS site auto submit form with page onload callback for checking authentication. It is not working with machanize gem.

Solution Manually submitting the form two times solves this issue. Example

url = 'http://www.mims.com/India/Browse/Alphabet/A?cat=drug'
page = agent.get url # here checking authentication if success then redirecting to destination
p page
page.form.submit
agent.page.form.submit
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top