为什么我得到一个不受支持的问题错误

时间:2022-12-31 22:47:40

I am writing a program that uses Mechanize to scrape a student's grades and classes from edline.net using a student account and return the data I need. However, after logging in, from the homepage I have to access a link (called 'Private Reports') which will then dynamically return a page of links to each of the student's classes and respective grades.

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

When testing I create a new object my_account that has several instance variables including the homepage. I pointed new variables to the instance variables for this to be more simple to read):

在测试时,我创建了一个新对象my_account,它有几个实例变量,包括主页。我将新变量指向实例变量,以便更简单地阅读):

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

result_page = agent.page.link_with(:text =>'Private Reports')。点击

I get:

Mechanize::UnsupportedSchemeError

But if I were to replace :click with :text it responds correctly and result_page will equal the link's text "Private Reports"

但如果我要替换:点击:文本它正确响应,result_page将等于链接的文本“私人报告”

Why does it respond to :text correctly but give an error for :click? Is there a way to get around this or should I rethink my solution to this problem?

为什么它会响应:文本正确但是给出错误:点击?有没有办法解决这个问题,还是应该重新考虑我对这个问题的解决方案?

Here's the code:

这是代码:

 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    

1 个解决方案

#1


Where does the link point to? Ie, what's the href?

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

I ask because "scheme" usually refers to something like http or https or ftp, so maybe the link has a weird scheme that mechanize doesn't know how to handle, hence Mechanize::UnsupportedSchemeError

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

#1


Where does the link point to? Ie, what's the href?

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

I ask because "scheme" usually refers to something like http or https or ftp, so maybe the link has a weird scheme that mechanize doesn't know how to handle, hence Mechanize::UnsupportedSchemeError

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

相关文章