ruby - 为什么我收到 unsupportedSchemeError

标签 ruby mechanize

我正在编写一个程序,该程序使用 Mechanize 使用学生帐户从 edline.net 中抓取学生的成绩和类(class)并返回我需要的数据。但是,登录后,我必须从主页访问一个链接(称为“私有(private)报告”),然后该链接将动态返回每个学生类(class)和各自成绩的链接页面。

测试时我创建了一个新对象 my_account它有几个实例变量,包括主页。我将新变量指向实例变量,以便更易于阅读):
result_page = agent.page.link_with(:text => 'Private Reports').click
我得到:
Mechanize::UnsupportedSchemeError
但如果我要替换 :click:text它正确响应并且 result_page将等于链接的文本“私有(private)报告”

为什么会回复:text正确但给出 :click 的错误?有没有办法解决这个问题,或者我应该重新考虑我对这个问题的解决方案吗?

这是代码:

 class AccountFetcher

     EDLINE_LOGIN_URL = 'http://edline.net/Index.page'

     def self.fetch_form(agent)

         # uses @agent of an Account object
         page = agent.get(EDLINE_LOGIN_URL)
         form = page.form('authenticationEntryForm')
     end


     # edline's login form has to have several pre-conditions met before submitting the form

     def self.initialize_form(agent)
         form = AccountFetcher.fetch_form(agent)
         submit_event = form.field_with(:name => 'submitEvent')
         enter_clicked = form.field_with(:name => 'enterClicked')
         ajax_support = form.field_with(:name => 'ajaxSupported')
         ajax_support.value = 'yes'
         enter_clicked.value = true
         submit_event.value = 1
         return form 
     end


     # logs the user in and returns the homepage

     def self.fetch_homepage(u_username, u_password, agent)
         form = AccountFetcher.initialize_form(agent)
         username = form.field_with(:name => 'screenName')
         password = form.field_with(:name => 'kclq')
         username.value = u_username
         password.value = u_password
         form.submit
     end
 end

 # class Account will be expanded later on but here are the bare bones for a user to log in to their account 
 class Account

     attr_accessor :report, :agent, :username, :password
     def initialize(u_username, u_password)
         @agent = Mechanize.new
         @username = u_username
         @password = u_password
     end

     def login
         page = AccountFetcher.fetch_homepage(self.username, self.password, self.agent) 
         @report = page
     end
 end 


 my_account = Account.new('ex_username', 'ex_password')
 my_account.login
 page = my_account.report
 agent = my_account.agent

 page = agent.page.link_with(:text => 'Private Reports').click    

最佳答案

链接指向哪里?即,href 是什么?

我问是因为“方案”通常是指诸如 http 或 https 或 ftp 之类的东西,所以也许链接有一个奇怪的方案, Mechanize 不知道如何处理,因此 Mechanize::UnsupportedSchemeError

关于ruby - 为什么我收到 unsupportedSchemeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30159748/

相关文章:

ruby-on-rails - 在现有数据库之上开始使用 ROR

ruby - 使用单个命令为多个 Ruby 版本运行 RSpec

python - 使用 Mechanize 导入 Cookie

mysql - 我想将整个 MySQL 表作为数组读入 ruby​​。我正在使用事件记录

ruby-on-rails - 在 Rails 中使用主机和多个路径字符串创建 URL

javascript - 尝试将 .js 文件添加到我的 Rails 应用程序时出现 ActionController::UnknownFormat

ruby - 如何使用具有随机生成的用户名和密码输入名称的表单登录

perl - 使用 Perl-Mechanize : finalizing a little programme 进行 Dom 处理

python - 在 HttpResponse() 调用后,Django View 没有得到完全处理

python-2.7 - 使用 python mechanize 填写选择控件