python webkit webview还记得饼干? [英] python webkit webview remember cookies?

查看:323
本文介绍了python webkit webview还记得饼干?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个短的python脚本,在web视图窗口中打开Goog​​le音乐。然而,我似乎没有找到任何关于让webkit使用cookie,所以我不必每次启动它时登录。

I have written a short python script that opens Google music in web view window. however I can't seem to find anything about getting webkit to use cookies so that I don't have to login every time I start it up.

这里是我有:

#!/usr/bin/env python
import gtk, webkit
import ctypes

libgobject = ctypes.CDLL('/usr/lib/i386-linux-gnu/libgobject-2.0.so.0')
libwebkit = ctypes.CDLL('/usr/lib/libsoup-2.4.so.1')
libsoup = ctypes.CDLL('/usr/lib/libsoup-2.4.so.1')
libwebkit = ctypes.CDLL('/usr/lib/libwebkitgtk-1.0.so.0')

proxy_uri = libsoup.soup_uri_new('http://tcdproxy.tcd.ie:8080') #proxy urli

session = libwebkit.webkit_get_default_session()
libgobject.g_object_set(session, "proxy-uri", proxy_uri, None)

w = gtk.Window()
w.connect("destroy",w.destroy)
w.set_size_request(1000,600)
w.connect('delete-event', lambda w, event: gtk.main_quit())
s = gtk.ScrolledWindow()
v = webkit.WebView()
s.add(v)
w.add(s)
w.show_all()

v.open('http://music.google.com')
gtk.main()

任何帮助将非常感谢,
感谢,

Any help on this would be greatly appreciated, thanks,

Richard

推荐答案

工作了,但它需要学习更多的ctypes比我想要的__-。尝试这个 - 我需要不同的库路径等等,所以我只需粘贴相关的。

Worked it out, but it required learning more ctypes than I wanted -_-. Try this- I required different library paths, etc than you, so I'll just paste what's relevant.

#remove all cookiejars
generic_cookiejar_type = libgobject.g_type_from_name('SoupCookieJar')
libsoup.soup_session_remove_feature_by_type(session, generic_cookiejar_type)

#and replace with a new persistent jar
cookiejar = libsoup.soup_cookie_jar_text_new('/path/to/your/cookies.txt',False)
libsoup.soup_session_add_feature(session, cookiejar)

代码很好解释。还有一个 SoupCookieJarSqlite ,您可能更喜欢,但我确定文本文件将更容易开发。

The code's pretty self explanatory. There's also a SoupCookieJarSqlite that you might prefer, though I'm sure the text file would be easier for development.

EDIT:实际上,cookie jar删除似乎没有做任何事情,所以适当的代码片段是

actually, the cookie jar removal doesn't seem to be doing anything, so the appropriate snippet is

#add a new persistent cookie jar
cookiejar = libsoup.soup_cookie_jar_text_new('/path/to/your/cookies.txt',False)
libsoup.soup_session_add_feature(session, cookiejar)

这篇关于python webkit webview还记得饼干?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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