Javascript redirect page jam mechanism

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:

# Logs into printer admin page and retrieved counts.
require 'rubygems'
require 'mechanize'
require 'logger'

# Create a new mechanize object
agent = Mechanize.new

# Load the printer admin page
page = agent.get("http://192.168.1.126/index.html?lang=1")

# Select the form with an action of index.cqi
form = agent.page.form_with(:action => "index.cgi")
form.radiobuttons_with(:id => '0x3fdb24153404')[1]

# Submit the form
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">
<!--
window.onload=function(){setTimeout(function(){document.menu_link.submit();},0);}
//-->
</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!

+3
source share
2 answers

. :

Basically Mechanise javascript, javascript ( 1) ( 2)

1 , POST of lang=1 , , .

- :

page = agent.post('http://192.168.1.126/index.html', {
  "lang" => "1"
})

Mechanize.

+1

, :

agent.follow_meta_refresh = true

, javascript , , . js. js, , .

, , ,

agent.post <url>

, , post.

:) node - node.js https://github.com/joshfire/node-crawler javascript .

0

All Articles