Note that there are some explanatory texts on larger screens.

plurals
  1. POMechanize getting stuck on Javascript redirect page
    primarykey
    data
    text
    <p>I am using Mechanize and Nokogiri in my Ruby on Rails application to scrape our local printers administration panel to retrieve the number of printed pages in the printers lifetime.</p> <p>I have the following rake task:</p> <pre><code># 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 =&gt; "index.cgi") form.radiobuttons_with(:id =&gt; '0x3fdb24153404')[1] # Submit the form page = form.submit form.buttons.first pp page </code></pre> <p>That returns the following:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"&gt; &lt;script type="text/javascript"&gt; &lt;!-- window.onload=function(){setTimeout(function(){document.menu_link.submit();},0);} //--&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="menu_link" action="index.html" method="post" enctype="application/x-www-form-urlencoded"&gt; &lt;input type="hidden" name="lang" value="1"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I don't seem to be able to select the form on the above page, and the script seems to stop at that page and not follow the redirect. </p> <p>Is there a standard way of working with these kind of redirects? Maybe pausing the script until the redirect has taken place? Would it every allow the redirect to work?</p> <p>Any pointers would be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload