Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9076337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:05:18+00:00 2026-06-16T19:05:18+00:00

I’m trying to store all cookies that I get from a website and than

  • 0

I’m trying to store all cookies that I get from a website and than print them.
Please help me to get it to work, because I think I don’t store anything, and that’s the reason why I have nothing on the output.

I’m testing this code on google website, and I’m pretty sure they store cookie once you get to there page.

So I’m trying to get all available cookies and print them. here is the code:

#! /usr/bin/env python2.7


from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtNetwork import *
from PyQt4.QtWebKit import *
import sys, os, simplejson, signal

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.tabs = QTabWidget()
        self.setCentralWidget(self.tabs)
        self.settings = QSettings()
        self.numberOfTabs = 0
        self.cookies = QNetworkCookieJar()
        self.cookies.setAllCookies([QNetworkCookie.parseCookies(c)[0] for c in self.get('cookiejar')])

    def put(self, key, value):
        self.settings.setValue(key, simplejson.dumps(value))
        self.settings.sync()

    def get(self, key):
        v = self.settings.value(key)
        return simplejson.loads(unicode(v.toString())) 

    def addNewTab(self, url=QUrl('')):
        self.numberOfTabs += 1
        self.tabs.setCurrentIndex(self.tabs.addTab(Tab(QUrl(url)),'%s'%str(self.numberOfTabs)))
        self.setCookies()
        return self.tabs.currentWidget()

    def setCookies(self):
        self.put('cookiejar', [str(c.toRawForm()) for c in self.cookies.allCookies()])
        print self.get('cookiejar')

class Tab(QWebView):
    def __init__(self, url):
        QWebView.__init__(self)
        self.load(url)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    browser = MainWindow()
    browser.addNewTab('https://google.com')
    browser.show()
    if signal.signal(signal.SIGINT, signal.SIG_DFL):
        sys.exit(app.exec_())
    app.exec_()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:05:19+00:00Added an answer on June 16, 2026 at 7:05 pm

    You should probably wait for loadFinished before checking for cookies, anyway, maybe something like this works for you, here I reimplement QNetworkCookieJar and do all the work of storing and loading cookies from there:

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    import sip
    sip.setapi('QString', 2)
    sip.setapi('QVariant', 2)
    
    from PyQt4 import QtCore, QtGui, QtWebKit, QtNetwork
    
    class cookieJar(QtNetwork.QNetworkCookieJar):
        def __init__(self, cookiesKey, parent=None):
            super(cookieJar, self).__init__(parent)
    
            self.mainWindow = parent
            self.cookiesKey = cookiesKey
            cookiesValue    = self.mainWindow.settings.value(self.cookiesKey)       
    
            if cookiesValue:
                cookiesList = QtNetwork.QNetworkCookie.parseCookies(cookiesValue)
                self.setAllCookies(cookiesList)
    
        def setCookiesFromUrl (self, cookieList, url):
            cookiesValue = self.mainWindow.settings.value(self.cookiesKey)
            cookiesArray = cookiesValue if cookiesValue else QtCore.QByteArray()
    
            for cookie in cookieList:
                cookiesArray.append(cookie.toRawForm() + "\n")
    
            self.mainWindow.settings.setValue(self.cookiesKey, cookiesArray)
    
            return super(cookieJar, self).setCookiesFromUrl(cookieList, url)
    
    class webView(QtWebKit.QWebView):
        def __init__(self, cookiesKey, url, parent=None):
            super(webView, self).__init__(parent)
    
            self.cookieJar = cookieJar(cookiesKey, parent)
    
            self.page().networkAccessManager().setCookieJar(self.cookieJar)
    
    class myWindow(QtGui.QMainWindow):
        def __init__(self, parent=None):
            super(myWindow, self).__init__(parent)
    
            self.cookiesKey = "cookies"
    
            self.centralwidget = QtGui.QWidget(self)
    
            self.tabWidget = QtGui.QTabWidget(self.centralwidget)
            self.tabWidget.setTabsClosable(True)
    
            self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
            self.verticalLayout.addWidget(self.tabWidget)
    
            self.actionTabAdd = QtGui.QAction(self)
            self.actionTabAdd.setText("Add Tab")
            self.actionTabAdd.triggered.connect(self.on_actionTabAdd_triggered)
    
            self.lineEdit = QtGui.QLineEdit(self)
            self.lineEdit.setText("http://www.example.com")
    
            self.toolBar = QtGui.QToolBar(self)
            self.toolBar.addAction(self.actionTabAdd)
            self.toolBar.addWidget(self.lineEdit)
    
            self.addToolBar(QtCore.Qt.ToolBarArea(QtCore.Qt.TopToolBarArea), self.toolBar)
            self.setCentralWidget(self.tabWidget)
    
            self.settings = QtCore.QSettings()
    
        @QtCore.pyqtSlot()
        def on_actionShowCookies_triggered(self):
            webView = self.tabWidget.currentWidget()
            listCookies = webView.page().networkAccessManager().cookieJar().allCookies()
    
            for cookie in  listCookies:
                print cookie.toRawForm()
    
        @QtCore.pyqtSlot()
        def on_actionTabAdd_triggered(self):
            url = self.lineEdit.text()
            self.addNewTab(url if url else 'about:blank')
    
        def addNewTab(self, url):
            tabName = u"Tab {0}".format(str(self.tabWidget.count()))
    
            tabWidget= webView(self.cookiesKey, url, self)
            tabWidget.loadFinished.connect(self.on_tabWidget_loadFinished)
            tabWidget.load(QtCore.QUrl(url))
    
            tabIndex = self.tabWidget.addTab(tabWidget, tabName)
    
            self.tabWidget.setCurrentIndex(tabIndex)
    
        @QtCore.pyqtSlot()
        def on_tabWidget_loadFinished(self):
            print self.settings.value(self.cookiesKey)
    
    if __name__ == "__main__":
        import sys
    
        app = QtGui.QApplication(sys.argv)
        app.setApplicationName('myWindow')
    
        main = myWindow()
        main.resize(666, 333)
        main.show()
    
        sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.