calling a simple PyQt application more than once

Jabba Laci jabba.laci at
Tue Jan 24 12:51:26 EST 2012


I have a simple PyQt application that creates a webkit instance to
scrape AJAX web pages. It works well but I can't call it twice. I
think the application is not closed correctly, that's why the 2nd call
fails. Here is the code below. I also put it on pastebin: .

The question is: how to call this code several times within a script.




import sys

from PyQt4.QtGui import QApplication
from PyQt4.QtWebKit import QWebPage
from PyQt4.QtCore import QUrl

class SimpleWebkit(QWebPage):
    def __init__(self, url): = QApplication(sys.argv)

    def save(self):
        self.html = self.mainFrame().toHtml()

def get_html(url):
    s = SimpleWebkit(url)
    return str(s.html)      # QString to string !


if __name__ == "__main__":
    url = ''
    print get_html(url)     # OK
    print '=========='
    print get_html(url)     # problem here, never called :(

More information about the Python-list mailing list