calling a simple PyQt application more than once

J

Jabba Laci

Hi,

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:
http://pastebin.com/gkgSSJHY .

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

Thanks,

Laszlo

=====

import sys

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

class SimpleWebkit(QWebPage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self.save)
self.mainFrame().load(QUrl(url))
self.app.exec_()

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

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

#####

if __name__ == "__main__":
url = 'http://simile.mit.edu/crowbar/test.html'
print get_html(url) # OK
print '=========='
print get_html(url) # problem here, never called :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top