3

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

scythargon
  • 3,363
  • 3
  • 32
  • 62
  • @arxanas I could not find in docs how to do that, I found http://webkitgtk.org/reference/webkit2gtk/unstable/WebKitCookieManager.html but nothing more – scythargon Aug 31 '12 at 18:08
  • @arxanas there is nothing about how to link my webkit.WebView() with this WebKitCookieManager – scythargon Aug 31 '12 at 18:11
  • Does this answer your question? [python webkit webview remember cookies?](https://stackoverflow.com/questions/7766445/python-webkit-webview-remember-cookies) – Blake Jan 19 '23 at 20:49

2 Answers2

8

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)
user871199
  • 1,420
  • 19
  • 28
0

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.

rise.riyo
  • 64
  • 5