我想从 http://www.mims.com/India/Browse/Alphabet/All?cat=Company&tab=company 收集制造商及其药品详细信息。
机械化gem用于在ryan教程的帮助下从html页面中提取内容
我可以成功登录,但无法到达 http://www.mims.com/India/Browse/Alphabet/All?cat=Company&tab=company 页面。
到目前为止我已经尝试过了
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
注意:我已经共享了虚拟登录凭据供您测试
单击"公司浏览公司目录"链接后,页面重定向并带有闪存消息"您正在重定向...",机械化宝石缓存此页面。
问题:
1(如何获取原始页面(重定向后(。
我发现了MIMS站点自动提交带有页面加载回调的表单以检查身份验证的问题案例。它不适用于机械化宝石。
溶液手动提交表单两次即可解决此问题。例
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