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.