mechanize 12306

firefox install plug-in  Export Cookies   详情: https://addons.mozilla.org/en-US/firefox/addon/export-cookies/

firefox 清除所有的 cookies

firefox 登录 12306

firefox export cookies  (save path:/home/xxx/cookies.txt)




require 'rubygems'

require 'mechanize'


a = Mechanize.new { |agent|
  agent.user_agent_alias = 'Windows IE 7'
  agent.ssl_version,agent.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE
}
a.cookie_jar.load_cookiestxt("/home/xxx/cookies.txt")


page = a.get('https://kyfw.12306.cn/otn/index/initMy12306')
document = Nokogiri::HTML(page.content)
puts document

你可能感兴趣的:(mechanize 12306)