0

I have been looking at the Requests documentation for a way to grab a site cookie for use elsewhere in my code. The documentation states the following:

If a response contains some Cookies, you can quickly access them:

>>> url = 'http://example.com/some/cookie/setting/url'
>>> r = requests.get(url)

>>> r.cookies['example_cookie_name']
'example_cookie_value'

I'm not sure however what would go inside the square brackets after r.cookies. If I try submitting with no square brackets at all I get the following output:

<<class 'requests.cookies.RequestsCookieJar'>[]>

Can anyone tell me what I need to do with the above to get the actual cookies returned back to me, please?

Thanks

EDIT:

In response to the first comment below, here is some example code, which is returning an empty dictionary for the cookie. Can anyone tell me why?

import requests, requests.utils

r = requests.get('http://www.whoscored.com/tournamentsfeed/12496/Fixtures/?d=2015W32&isAggregate=false')
session = requests.session()
rr = requests.utils.dict_from_cookiejar(session.cookies)
print rr
gdogg371
  • 3,879
  • 14
  • 63
  • 107

1 Answers1

0

The site you are trying to get cookies from does not appear to exist. If I substitute a different website in your code:

import requests, requests.utils

r = requests.get('http://google.com')  # using google.com
print(r.cookies.keys())

Output:

['NID']
Ben P
  • 115
  • 9