Advertisement
Guest User

Untitled

a guest
Jan 24th, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import sys
  2.  
  3. from PyQt4.QtGui import QApplication
  4. from PyQt4.QtWebKit import QWebPage
  5. from PyQt4.QtCore import QUrl
  6.  
  7.  
  8. class SimpleWebkit(QWebPage):
  9.     def __init__(self, url):
  10.         self.app = QApplication(sys.argv)
  11.         QWebPage.__init__(self)
  12.         self.loadFinished.connect(self.save)
  13.         self.mainFrame().load(QUrl(url))
  14.         self.app.exec_()
  15.        
  16.     def save(self):
  17.         self.html = self.mainFrame().toHtml()
  18.         self.app.quit()
  19.  
  20.  
  21. def get_html(url):  
  22.     s = SimpleWebkit(url)
  23.     return str(s.html)      # QString to string !
  24.  
  25. #############################################################################
  26.  
  27. if __name__ == "__main__":
  28.     url = 'http://simile.mit.edu/crowbar/test.html'
  29.     print get_html(url)     # OK
  30.     print '=========='
  31.     print get_html(url)     # never called :(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement