Ruby Mechanize登录无法正常工作 [英] Ruby Mechanize login not working

查看:110
本文介绍了Ruby Mechanize登录无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我为我要完成的任务做好准备.在我参加的物理课程中,我的老师总是喜欢吹嘘在课堂上作弊是多么不可能,因为她的所有作业都是通过WebAssign完成的. WebAssign的工作方式是这样的:每个人都遇到相同的问题,但是问题中使用的数字是随机变量,因此每个学生都有不同的数字,因此答案也不同.因此,我一直在编写ruby脚本,只需输入您的具体数字即可解决人们的问题.

Let me set the stage for what I'm trying to accomplish. In a physics class I'm taking, my teacher always likes to brag about how impossible it is to cheat in her class, because all of her assignments are done through WebAssign. The way WebAssign works is this: Everyone gets the same questions, but the numbers used in the question are random variables, so each student has different numbers, thus a different answer. So I've been writing ruby scripts to solve the question's for people by just imputing your specific numbers.

我想使用机械化来自动执行此过程.以前,我已经进行过许多次机械化操作,但是登录该站点时遇到了麻烦.我将提交表单,它返回与我刚上过的页面相同的页面.您可以在 http://webassign.net 上查看网站的源代码,我也尝试使用在 http://webassign.net/login.html 上的登录名也没有运气.

I would like to automate this process using mechanize. I've used mechanize plenty of times before, but I'm having trouble logging in to the site. I'll submit the form and it returns the same page I was just on. You can take a look at the site's source code, at http://webassign.net, and I've also tried using the login at http://webassign.net/login.html with no luck either.

让我用一些红宝石代码来跟踪所有这些事情,这些代码无法满足我的期望:

Let me follow all of this up with some ruby code that doesn't do what I want it to:

require 'rubygems'
require 'mechanize'

agent = Mechanize.new

page = agent.get("http://www.webassign.net/login.html")
form = page.forms.last
puts "Enter your username"
form.WebAssignUsername = gets.chomp
puts "Enter your password (Don't worry, we don't save this)"
form.WebAssignPassword = gets.chomp
form.WebAssignInstitution = "trinityvalley.tx"

form.submit #=> Returns original page 

如果有人真的有兴趣让它生效,那么我很乐意向他们发送有效的用户名和密码.

If anyone really takes an interest in getting this to work, I would be more than happy to send them a working username and password.

推荐答案

该站点可能正在检查是否已设置Login post变量(请参见登录按钮).尝试添加form.Login = "Login".

The site could be checking that the Login post variable is set (see the login button). Try adding form.Login = "Login".

这篇关于Ruby Mechanize登录无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆