analyticsPierce analyticsPierce - 8 months ago 68
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.


Assuming the script isn't really reformatted like that:

url = page.body[/url = '(.*?)'/, 1]
page = @agent.get url