有没有办法将cookie附加到已经制作和使用过的openerdirector对象中?
答案 0 :(得分:0)
试试这个:
import urllib2
import cookielib
# load cookies from file
saved_cookies = cookielib.MozillaCookieJar('cookie_file_name')
saved_cookies.load()
opener = urllib2.build_opener() # your opener director
# do something...
opener.add_handler(urllib2.HTTPCookieProcessor(saved_cookies))
编辑:根据Python cookielib document,旧的cookie会被保留,除非被新加载的cookie覆盖。