I use Mechanize and Nokogiri in the Ruby on Rails application to clear the local printer admin panel to get the number of printed pages over the life of the printers.
I have the following rake task:
require 'rubygems'
require 'mechanize'
require 'logger'
agent = Mechanize.new
page = agent.get("http://192.168.1.126/index.html?lang=1")
form = agent.page.form_with(:action => "index.cgi")
form.radiobuttons_with(:id => '0x3fdb24153404')[1]
page = form.submit form.buttons.first
pp page
This returns the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<script type="text/javascript">
</script>
</head>
<body>
<form name="menu_link" action="index.html" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="lang" value="1">
</form>
</body>
</html>
It seems I can not select the form on the page above, and the script seems to stop on this page and should not be redirected.
Is there a standard way to deal with such redirects? Maybe pause the script until a redirect occurs? Will everyone allow redirection to work?
Any pointers would be appreciated!
source
share