문제

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).

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top