gpt4 book ai didi

Ruby Mechanize 在响应中忽略 cookie

转载 作者:行者123 更新时间:2023-12-04 16:22:31 27 4
gpt4 key购买 nike

我正在玩 Ruby Mechanize 网站。但它似乎忽略了响应中的 set-cookie header 之一。请看我的代码和结果。 agent.cookies 的结果中缺少 u=__LOGOUT__ 部分。为什么?谢谢。

require 'mechanize'
require 'logger'
agent = Mechanize.new
agent.user_agent_alias = 'Windows IE 9'
agent.follow_meta_refresh = true
agent.log = Logger.new(STDOUT)

cookie = Mechanize::Cookie.new("__utmarea", "404-0-1")
cookie.domain = '.youku.com'
cookie.path = '/'
agent.cookie_jar.add(URI.parse("http://www.youku.com/"), cookie)

page = agent.get("http://www.youku.com/index_login/", :referer => "http://www.youku.com/")
puts agent.cookies.to_s

这是我执行上面代码时的结果。
F:\Dropbox\temp>ruby youku.rb
I, [2012-03-02T11:52:15.398550 #3188] INFO -- : Net::HTTP::Get: /index_login/?referer=http%3A%2F%2Fwww.youku.com%2F
D, [2012-03-02T11:52:15.399550 #3188] DEBUG -- : request-header: accept => */*
D, [2012-03-02T11:52:15.400550 #3188] DEBUG -- : request-header: user-agent => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
D, [2012-03-02T11:52:15.401550 #3188] DEBUG -- : request-header: accept-encoding => gzip,deflate,identity
D, [2012-03-02T11:52:15.402550 #3188] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
D, [2012-03-02T11:52:15.403550 #3188] DEBUG -- : request-header: accept-language => en-us,en;q=0.5
D, [2012-03-02T11:52:15.403550 #3188] DEBUG -- : request-header: cookie => __utmarea=404-0-1
D, [2012-03-02T11:52:15.404550 #3188] DEBUG -- : request-header: host => www.youku.com
I, [2012-03-02T11:52:15.699565 #3188] INFO -- : status: Net::HTTPOK 1.1 200 OK
D, [2012-03-02T11:52:15.700565 #3188] DEBUG -- : response-header: server => Apache
D, [2012-03-02T11:52:15.701565 #3188] DEBUG -- : response-header: set-cookie => YOUKUSESSID=g9db0qlosehrvao5o825oh5455; path=/; domain=.youku.com, u=__LOGOUT__; expires=Thu, 01-Jan-1970 00:00:01 GMT;
path=/; domain=.youku.com
D, [2012-03-02T11:52:15.702565 #3188] DEBUG -- : response-header: expires => Thu, 19 Nov 1981 08:52:00 GMT
D, [2012-03-02T11:52:15.702565 #3188] DEBUG -- : response-header: cache-control => no-store, no-cache, must-revalidate
D, [2012-03-02T11:52:15.703566 #3188] DEBUG -- : response-header: pragma => no-cache
D, [2012-03-02T11:52:15.704566 #3188] DEBUG -- : response-header: vary => Accept-Encoding
D, [2012-03-02T11:52:15.704566 #3188] DEBUG -- : response-header: content-encoding => gzip
D, [2012-03-02T11:52:15.705566 #3188] DEBUG -- : response-header: content-type => text/html; charset=UTF-8
D, [2012-03-02T11:52:15.705566 #3188] DEBUG -- : response-header: content-length => 1724
D, [2012-03-02T11:52:15.706566 #3188] DEBUG -- : response-header: date => Fri, 02 Mar 2012 03:52:19 GMT
D, [2012-03-02T11:52:15.707566 #3188] DEBUG -- : response-header: age => 0
D, [2012-03-02T11:52:15.707566 #3188] DEBUG -- : response-header: connection => keep-alive
D, [2012-03-02T11:52:15.708566 #3188] DEBUG -- : response-header: x-cache => Miss from a05.www
D, [2012-03-02T11:52:15.709566 #3188] DEBUG -- : Read 1724 bytes (1724 total)
D, [2012-03-02T11:52:15.710566 #3188] DEBUG -- : gzip response
D, [2012-03-02T11:52:15.713566 #3188] DEBUG -- : saved cookie: YOUKUSESSID=g9db0qlosehrvao5o825oh5455
D, [2012-03-02T11:52:15.717566 #3188] DEBUG -- : saved cookie: u=__LOGOUT__
[__utmarea=404-0-1, YOUKUSESSID=g9db0qlosehrvao5o825oh5455]

F:\Dropbox\temp>

最佳答案

因为该 cookie 的过期时间是 'Thu, 01-Jan-1970 00:00:01 GMT'

关于Ruby Mechanize 在响应中忽略 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9527776/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com