1

我使用 cookies.txt Chrome 插件从 Chrome 导出了 cookie。我可以使用 curl 和导出的 cookie 轻松地重播请求。一些类似的代码curl -b mycookie.txt -c mycookie.txt $url可以完美运行。

但是,当我尝试使用请求从 mycookie.txt 加载会话时,它无法工作。经过长时间的调试,我喜欢请求不会发送会话cookie(cookie文件中的过期值为0),即使我已经使用以下代码加载了过期的cookie:

cj = cookielib.MozillaCookieJar('mycookie.txt')
cj.load(ignore_discard=True, ignore_expires=True)
print cj  #it shows the session cookie already loaded

s = requests.Session()
s.cookies = cj
r = s.get(url, headers=myheaders, timeout=10, allow_redirects=False)
print r.request.headers   #this clearly shows the request didn't send the session cookie

我怎样才能让它工作?

4

0 回答 0