not getting all cookie info using python requests module -


i'm learning how login example website using python requests module. video tutorial got me started. cookies see in googlechrome>inspect element>networktab, i'm not able retrieve of them using following code:

import requests requests.session() s:     url = 'http://www.noobmovies.com/accounts/login/?next=/'     s.get(url)     allcookies = s.cookies.get_dict()     print allcookies 

using csrftoken below:

{'csrftoken': 'epe8zgxv4yhj5j1nogbxnhlk1fq4jwqo'} 

but in google chrome, see these other cookies apart csrftoken (sessionid, _gat, _ga etc): google chrome screenshot

i tried following code here, result same:

from urllib2 import request, build_opener, httpcookieprocessor, httphandler import cookielib  #create cookiejar object hold cookies cj = cookielib.cookiejar() #create opener open pages using http protocol , process cookies. opener = build_opener(httpcookieprocessor(cj), httphandler())  #create request object used page. req = request("http://www.noobmovies.com/accounts/login/?next=/") f = opener.open(req)  #see first few lines of page html = f.read() print html[:50]  #check out cookies print "the cookies are: " cookie in cj:     print cookie 

output:

<!doctype html> <html xmlns="http://www.w3.org cookies are:  <cookie csrftoken=epe8zgxv4yhj5j1nogbxnhlk1fq4jwqo www.noobmovies.com/> 

so, how can cookies ? thanks.

the cookies being set other pages/resources, loaded javascript code. can check making request page (without running js code), using tools such wget, curl or httpie.

the cookie server set csrftoken, can see in:

$ wget --server-response 'http://www.noobmovies.com/accounts/login/?next=/' --2016-02-01 22:51:55--  http://www.noobmovies.com/accounts/login/?next=/ resolving www.noobmovies.com (www.noobmovies.com)... 69.164.217.90 connecting www.noobmovies.com (www.noobmovies.com)|69.164.217.90|:80... connected. http request sent, awaiting response...    http/1.1 200 ok   server: nginx/1.4.6 (ubuntu)   date: tue, 02 feb 2016 00:51:58 gmt   content-type: text/html; charset=utf-8   transfer-encoding: chunked   connection: keep-alive   vary: accept-encoding   expires: tue, 02 feb 2016 00:51:58 gmt   vary: cookie,accept-encoding   cache-control: max-age=0   set-cookie: csrftoken=xj07swhmpt1hqv4k96lxkydwayift1w5; expires=tue, 31-jan-2017 00:51:58 gmt; max-age=31449600; path=/   last-modified: tue, 02 feb 2016 00:51:58 gmt length: unspecified [text/html] saving to: ‘index.html?next=%2f’  index.html?next=%2f             [      <=>                                   ]  10,83k  2,93kb/s    in 3,7s      2016-02-01 22:52:03 (2,93 kb/s) - ‘index.html?next=%2f’ saved [11085] 

note set-cookie line.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -