python - how do I insert a cookie into a urllib2 openerdirector object? -
is there way append cookie made , used openerdirector object?
try this:
import urllib2 import cookielib # load cookies file saved_cookies = cookielib.mozillacookiejar('cookie_file_name') saved_cookies.load() opener = urllib2.build_opener() # opener director # something... opener.add_handler(urllib2.httpcookieprocessor(saved_cookies))
edit: according python cookielib document, old cookies kept unless overwritten newly loaded ones.
Comments
Post a Comment