gpt4 book ai didi

ruby - 为什么我收到 unsupportedSchemeError

转载 作者:行者123 更新时间:2023-12-04 16:21:42 25 4
gpt4 key购买 nike

我正在编写一个程序,该程序使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com