Reputation: 27632
I need to access a few HTML pages through a Python 3 script, problem is that I need COOKIE functionality, therefore a simple urllib HTTP request won't work.
Any ideas?
Upvotes: 3
Views: 1723
Reputation: 28036
python3's urllib has cookie support, look at urllib.request.HTTPCookieProcessor, and http.cookiejar
Upvotes: 4
Reputation: 165312
Use requests.
>>> import requests
>>> url = 'http://httpbin.org/cookies/set/requests-is/awesome'
>>> r = requests.get(url)
>>> print r.cookies
{'requests-is': 'awesome'}
Reference: http://docs.python-requests.org/en/latest/user/quickstart/#cookies
As of a few days ago, requests supports Python 3, though you might have to use one of the develop
branches, not entirely sure about the status of upstream integration.
Upvotes: 3