#!/usr/bin/env python
# coding=utf-8
import urllib2
import cookielib

filename = "cookie.txt"
cookie = cookielib.MozillaCookieJar(filename)
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
response = opener.open("http://www.baidu.com")
cookie.save(ignore_discard=True, ignore_expires=True)
file = open("baidu.html", 'w')
try:
    file.write(response.read())
finally:
    file.close()
