Ruby 机械化 gem 未遵循元刷新
Ruby Mechanize gem not following meta refresh
我有一个 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=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,并没有遵循元刷新。任何关于我如何遵循的建议将不胜感激。
假设脚本没有像那样重新格式化:
url = page.body[/url = '(.*?)'/, 1]
page = @agent.get url
我有一个 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=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,并没有遵循元刷新。任何关于我如何遵循的建议将不胜感激。
假设脚本没有像那样重新格式化:
url = page.body[/url = '(.*?)'/, 1]
page = @agent.get url