Ruby Mechanize gem不遵循元刷新

时间:2016-11-20 23:33:58

标签: ruby mechanize

我有一个Ruby 2.2自动化脚本,它使用Mechanize登录Google Payments。当我尝试访问url时,在元刷新上停止了Mechanize。页面内容为:

<!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&#61;billing&amp;passive&#61;1209600&amp;continue&#61;https://payments.google.com
 /payments/home&amp;followup&#61;https://payments.google.com/payments/home'"></meta>
</noscript></head>

<body></body>
</html>

以下是我的脚本进入登录界面的部分:

@agent = Mechanize.new  
@agent.follow_meta_refresh = true  
page = @agent.get("http://payments.google.com/payments/home")  
puts page.content

最后的page.content只显示上面的html,不遵循元刷新。关于如何遵循这一点的任何建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

假设脚本没有真正重新格式化:

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