Use of cookies and urllib2 :
import cookielib import urllib2 cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
You can use the same opener for multiple connections:
data = [opener.open(url).read() for url in urls]
Or install it globally:
urllib2.install_opener(opener)
In the latter case, the rest of the code looks the same with or without cookie support:
data = [urllib2.urlopen(url).read() for url in urls]
source share