june2014

#模拟登陆百度空间,获得最开始登陆百度空间网页返回的cookie
import cookielib,urllib,urllib2

loginUrl=\'http://hi.baidu.com/motionhouse\'
cj=cookielib.CookieJar()  #新建CookieJar实例,用于保存cookie
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))  #处理cookie并生成opener
urllib2.install_opener(opener)  #安装使用opener
resp=urllib2.urlopen(loginUrl)  #打开地址
for index,cookie in enumerate(cj):
    print \'[\',index,\']\',cookie
    print cookie.name
    print cookie.value
    print cookie.expires
    print cookie.path
    print cookie.comment
    print cookie.domain
    #print cookie.max-age
    print cookie.secure
    print cookie.version
    #print cookie.httponly

分类:

技术点:

相关文章: