我怎样才能使 Python 的模块机械化(特别是 mechanize.Browser())以将其当前的 cookie 保存到人类可读的文件中?另外,我将如何将该 cookie 上传到带有它的网页?
谢谢
最佳答案
Deusdies,我刚刚找到了一种引用 Mykola Kharechko 的 post 的方法
#to save cookie
>>>cookiefile=open('cookie','w')
>>>cookiestr=''
>>>for c in br._ua_handlers['_cookies'].cookiejar:
>>> cookiestr+=c.name+'='+c.value+';'
>>>cookiefile.write(cookiestr)
#binding this cookie to another Browser
>>>while len(cookiestr)!=0:
>>> br1.set_cookie(cookiestr)
>>> cookiestr=cookiestr[cookiestr.find(';')+1:]
>>>cookiefile.close()
关于python - 如何将 mechanize.Browser() cookie 保存到文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7510806/