python webkit webview remember cookies?

后端 未结 2 1802
孤独总比滥情好
孤独总比滥情好 2020-12-06 08:23

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

2条回答
  •  天命终不由人
    2020-12-06 09:10

    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)
    

    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: 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)
    

提交回复
热议问题