Reputation: 3025
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>
<html>
<head>
<title>Redirecting...</title>
<script type="text/javascript" language="javascript">
var url = 'https:\/\/accounts.google.com\/ServiceLogin?
service\x3dbilling\x26passive\x3d1209600\x26continue\x3dhttps:\/\/payments.google.com\/
payments\/home%23__HASH__\x26followup\x3dhttps:\/\/payments.google.com\/payments\/
home'; var fragment = ''; if (self.document.location.hash) {fragment = self.document.
location.hash.replace(/^#/,'');}url = url.replace(new RegExp("__HASH__", 'g'),
encodeURIComponent(fragment));window.location.assign(url);
</script><noscript><meta
http-equiv="refresh" content="0; url='https://accounts.google.com/ServiceLogin?
service=billing&passive=1209600&continue=https://payments.google.com
/payments/home&followup=https://payments.google.com/payments/home'"></meta>
</noscript></head>
<body></body>
</html>
Here is the part of my script to get to the login screen:
@agent = Mechanize.new
@agent.follow_meta_refresh = true
page = @agent.get("http://payments.google.com/payments/home")
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.
Upvotes: 0
Views: 212
Reputation: 55002
Assuming the script isn't really reformatted like that:
url = page.body[/url = '(.*?)'/, 1]
page = @agent.get url
Upvotes: 1