屏幕抓取Akamai的控制面板使用Mechanize for Ruby - Cookies问题

时间:2011-09-02 22:28:39

标签: ruby screen-scraping nokogiri mechanize

我试图屏蔽来自Akamai控制面板的一些数据,但是我在通过机械化为Ruby登录页面时遇到了麻烦。

require 'rubygems'
require 'mechanize'

agent = Mechanize.new

url = 'http://control.akamai.com'
page = agent.get( url )

puts page.content

检查页面后,我发现显示:

"Cookie support has been disabled in your browser. Please enable cookies before continuing."

页面认为我禁用了cookie这一事实阻止了我登录。有什么想法吗?

1 个答案:

答案 0 :(得分:6)

您可以指定其他用户代理:

agent.user_agent_alias = 'Mac Safari'

或/并手动创建一个cookie:

cookie = Mechanize::Cookie.new(key, value)
cookie.domain = '.akamai.com'
cookie.path = '/'
agent.cookie_jar.add(cookie)

有关Ruby Mechanize cookie的更多信息,请阅读以下页面:

http://mechanize.rubyforge.org/Mechanize/Cookie.html http://mechanize.rubyforge.org/Mechanize/CookieJar.html