如何读取Python中的所有Cookie,而不知道他们的名字? 不知道这是你正在寻找的,但这里是一个简单的例子,你将Cookie放在一个cookiejar中并读回来: from urllib2 import Request, build_opener, HTTPCooki
from urllib2 import Request, build_opener, HTTPCookieProcessor, HTTPHandler import cookielib #Create a CookieJar object to hold the cookies cj = cookielib.CookieJar() #Create an opener to open pages using the http protocol and to process cookies. opener = build_opener(HTTPCookieProcessor(cj), HTTPHandler()) #create a request object to be used to get the page. req = Request("http://www.about.com") f = opener.open(req) #see the first few lines of the page html = f.read() print html[:50] #Check out the cookies print "the cookies are: " for cookie in cj: print cookie