webkit: is it possible to store cookies to file and reuse it again?

北战南征 提交于 2020-01-02 08:29:42

问题


is it possible to store cookies to file when you use webkit and reuse it again next time when I run my application?


回答1:


I know its old question and have been looking for the answer all over the place. Finally came up on my own after some trial and error. Hope this helps others.

from gi.repository import Soup
cookiejar = Soup.CookieJarText.new("<Your cookie path>", False)
cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)
session = WebKit.get_default_session()
session.add_feature(cookiejar)



回答2:


For those using WebKit and Gtk, change the first line from:

from gi.repository import Soup

to:

from gi.repository import Gtk, WebKit, Soup

to avoid static and dynamic conflicts.



来源:https://stackoverflow.com/questions/12220373/webkit-is-it-possible-to-store-cookies-to-file-and-reuse-it-again

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!