I am attempting to s开发者_如何学Gocreen scrape some data from Akamai's control panel, but I am having trouble while logging in to the page via mechanize for Ruby.
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
url = 'http://control.akamai.com'
page = agent.get( url )
puts page.content
Upon examining the page, I find displayed:
"Cookie support has been disabled in your browser. Please enable cookies before continuing."
The fact that the page thinks I have cookies disabled prevents me from logging in. Any thoughts?
You can specify other user agent:
agent.user_agent_alias = 'Mac Safari'
Or/And create a cookie manually:
cookie = Mechanize::Cookie.new(key, value)
cookie.domain = '.akamai.com'
cookie.path = '/'
agent.cookie_jar.add(cookie)
For more info about Ruby Mechanize cookies, read this pages:
http://mechanize.rubyforge.org/Mechanize/Cookie.html http://mechanize.rubyforge.org/Mechanize/CookieJar.html
精彩评论