Created
January 12, 2021 09:55
-
-
Save 11philip22/b717357a0c4f78281ed13e138ad8451a to your computer and use it in GitHub Desktop.
python render js headless https://webscraping.com/blog/Scraping-JavaScript-webpages-with-webkit/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt4.QtGui import * | |
from PyQt4.QtCore import * | |
from PyQt4.QtWebKit import * | |
class Render(QWebPage): | |
def __init__(self, url): | |
self.app = QApplication(sys.argv) | |
QWebPage.__init__(self) | |
self.loadFinished.connect(self._loadFinished) | |
self.mainFrame().load(QUrl(url)) | |
self.app.exec_() | |
def _loadFinished(self, result): | |
self.frame = self.mainFrame() | |
self.app.quit() | |
url = 'http://webscraping.com' | |
r = Render(url) | |
html = r.frame.toHtml() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment