为什么我会收到 unsupportedSchemeError

Why am I getting an unsupportedSchemeError

我正在编写一个程序,该程序使用 Mechanize 从 edline.net 中使用学生帐户和 return 我需要的数据来抓取学生的成绩和 类。但是,登录后,我必须从主页访问一个 link(称为 'Private Reports'),然后动态地 return 每个学生的 link 页面类 和各自的成绩。

测试时,我创建了一个新对象 my_account,它有几个实例变量,包括主页。我将新变量指向实例变量以使其更易于阅读):

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

我得到:

Mechanize::UnsupportedSchemeError

但是如果我用 :text 替换 :click 它会正确响应并且 result_page 将等于 link 的文本 "Private Reports"

为什么它对 :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    

link 指向哪里?即,href 是什么?

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