문제

저는 웹 사이트로 루비 기계화 을 가지고 노는 것입니다.그러나 그것은 응답에서 세트 쿠키 헤더 중 하나를 무시하는 것 같습니다.내 코드와 결과를 참조하십시오.agentacodicetagode 부분이 에이전트의 결과가 누락되었습니다.왜?고마워.

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>
.

도움이 되었습니까?

해결책

Because that cookie's expires is 'Thu, 01-Jan-1970 00:00:01 GMT'

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top