我的朋友写了一个脚本,它使用 ruby 的 mechanize 在登录后从页面中获取 cookie。
- 开始机械化
- 通过登录
- 从表单传递的页面中获取 cookie 值
剧本似乎对他有用,但对我不起作用。我尝试过以交互方式执行此操作,但我注意到 Mechanize 返回的页面标题与浏览器返回的页面标题不同。当我登录时,页面标题是“SSL VPN - Home”,但是当我查看返回的提交对象的标题属性时,我得到“请稍候...”
irb(main):084:0> intermediate.title
=> "Please wait..."
irb(main):085:0> intermediate.iframes
=> [#<Mechanize::Page::Frame nil "/dana-na/html/blank.html">
Mechanize 是否可能没有等待足够长的时间来获取目标页面?“请稍候...”似乎暗示某个中间页面被刷新或重定向,而 Mechanize 会话没有到达。无论哪种方式,我都没有得到相同的标题值。
=> #<Mechanize::Page
{url
#<URI::HTTPS:0x00000002b49338 URL:https://vpn1.example.com/dana/home/starter0.cgi?check=yes>}
{meta_refresh}
{title "Please wait..."}
{iframes #<Mechanize::Page::Frame nil "/dana-na/html/blank.html">}
{frames}
{links}
{forms
#<Mechanize::Form
{name "frmGrab"}
{method "POST"}
{action "/dana/home/starter0.cgi"}
{fields
[hidden:0x15b9860 type: hidden name: xsauth value: a0395604a9f4f531504a7f6b6dc86051]
[hidden:0x15b94a0 type: hidden name: tz_offset value: ]
[hidden:0x15b92e8 type: hidden name: clienttime value: ]
[hidden:0x15b8ff0 type: hidden name: url value: ]
[hidden:0x15b8ac8 type: hidden name: activex_enabled value: 0]
[hidden:0x15b8898 type: hidden name: java_enabled value: 0]
[hidden:0x15b8690 type: hidden name: power_user value: 0]
[hidden:0x15b84ec type: hidden name: grab value: 1]
[hidden:0x15b8348 type: hidden name: browserproxy value: ]
[hidden:0x15b8168 type: hidden name: browsertype value: ]
[hidden:0x15b7fb0 type: hidden name: browserproxysettings value: ]
[hidden:0x15b7df8 type: hidden name: check value: yes]
[hidden:0x15b7c54 type: hidden name: nextpage value: ]
[hidden:0x15bb8f4 type: hidden name: mid value: ]
[hidden:0x15bb5d4 type: hidden name: signin value: ]
[hidden:0x15bb2dc type: hidden name: alias value: ]
[hidden:0x15bb05c type: hidden name: id value: ]
[hidden:0x15baeb8 type: hidden name: username value: ]
[hidden:0x15bacb0 type: hidden name: password value: ]
[hidden:0x15bab20 type: hidden name: occurrence value: ]}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons}>}>