Python:如何dump一个mechanize.Browser实例的cookie? [英] Python: how to dump cookies of a mechanize.Browser instance?

查看:243
本文介绍了Python:如何dump一个mechanize.Browser实例的cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何使用机械化,一个自动与网站交互的Python模块。 / p>

一个功能是自动处理Cookie。我想从 mechanize.Browser 实例中转储cookie以进行调试,但我似乎无法自己解决。

解决方案

 

>>>从机械化导入浏览器
>>> b = Browser()
>>> b._ua_handlers ['_ cookies']。cookiejar
mechanize._clientcookie.CookieJar []
>>> b.open('http://google.com ')
response_seek_wrapper at 0xb7a922ccL其包装对象= closeable_response在0xb7aa070cL其fp = socket._fileobject对象在0xb7a94224
>>>
>>> b._ua_handlers ['_ cookies']。cookiejar
mechanize._clientcookie.CookieJar [Cookie(version = 0,name ='PREF',value ='ID = 57d545c229b4cf3f:TM = 1236081634:LM = 1236081634:S = p001WJMOr-V8Rlvi',port = None,port_specified = False ,domain ='。google.com',domain_specified = True,domain_initial_dot = True,path ='/',path_specified = True,secure = False,expires = 1299153634,discard = False,comment = None,comment_url = None,rest = {},rfc2109 = False),Cookie(version = 0,name ='PREF',value ='ID = 20534d80a5ccf2ea:TM = 1236081635:LM = 1236081635:S = jW3UotZ0dg8sv6mf',port = None,port_specified = False,domain = '.google.com.ua',domain_specified = True,domain_initial_dot = True,path ='/',path_specified = True,secure = False,expires = 1299153635,discard = False,comment = None,comment_url = None,rest = },rfc2109 = False)]
>>>


I am learning how to use mechanize, a Python module to automate interacting with websites.

One feature is the automated handling of cookies. I would to want to dump cookies from a mechanize.Browser instance for debugging purposes, but I can't seem to figure this out myself.

解决方案


>>> from mechanize import Browser
>>> b = Browser()
>>> b._ua_handlers['_cookies'].cookiejar
mechanize._clientcookie.CookieJar[]
>>> b.open('http://google.com')
response_seek_wrapper at 0xb7a922ccL whose wrapped object = closeable_response at 0xb7aa070cL whose fp = socket._fileobject object at 0xb7a94224
>>>
>>> b._ua_handlers['_cookies'].cookiejar
mechanize._clientcookie.CookieJar[Cookie(version=0, name='PREF', value='ID=57d545c229b4cf3f:TM=1236081634:LM=1236081634:S=p001WJMOr-V8Rlvi', port=None, port_specified=False, domain='.google.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=False, expires=1299153634, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='PREF', value='ID=20534d80a5ccf2ea:TM=1236081635:LM=1236081635:S=jW3UotZ0dg8sv6mf', port=None, port_specified=False, domain='.google.com.ua', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=False, expires=1299153635, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]
>>>                           

这篇关于Python:如何dump一个mechanize.Browser实例的cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆