【发布时间】:2016-11-20 23:33:57
【问题描述】:
我有一个使用 Mechanize 登录 Google Payments 的 Ruby 2.2 自动化脚本。当我尝试访问 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=billing&passive=1209600&continue=https://payments.google.com
/payments/home&followup=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,没有跟着meta刷新。任何关于我如何遵循的建议将不胜感激。
【问题讨论】:
-
@Idempotence 我认为您的想法是正确的,但我自己 reformatted 是,因为这比校对更快。
-
你实际上不能像这样在 url 中有换行符,它会破坏脚本。
-
@pguardiario 有人认为将返回值的原始帖子格式化会很聪明。原始网址不包含换行符。
-
是的,我就是这么想的 :) @jpaugh 有点过分热心了。
-
@analyticsPierce, @pguardiario 我很抱歉!我使用了一个自动化工具来重新格式化它,但如果它坏了,请恢复。