analyticsPierce analyticsPierce - 1 year ago 151
Ruby Question

Ruby Mechanize gem not following meta refresh

I have a Ruby 2.2 automation script that uses Mechanize to log in to Google Payments. When I try to access the url Mechanize stops on the meta refresh. The content of the page is:

<!DOCTYPE html>
<script type="text/javascript" language="javascript">
var url = 'https:\/\/\/ServiceLogin?
home'; var fragment = ''; if (self.document.location.hash) {fragment = self.document.
location.hash.replace(/^#/,'');}url = url.replace(new RegExp("__HASH__", 'g'),
http-equiv="refresh" content="0; url='


Here is the part of my script to get to the login screen:

@agent =
@agent.follow_meta_refresh = true
page = @agent.get("")
puts page.content

The page.content at the end only shows the above html, the meta refresh is not followed. Any suggestions on how I can follow that would be greatly appreciated.

Answer Source

Assuming the script isn't really reformatted like that:

url = page.body[/url = '(.*?)'/, 1]
page = @agent.get url
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download