I am new to Python and am trying to understand why I am getting the following error:
Traceback (most recent call last):
File "WebScraper.py", line 10, in <module>
class Render(QWebPage):
NameError: name 'QWebPage' is not defined
Here is the code:
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from lxml import html
#Take this class for granted.Just use result of rendering.
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://pycoders.com/archive/'
r = Render(url)
result = r.frame.toHtml()
#This step is important.Converting QString to Ascii for lxml to process
archive_links = html.fromstring(str(result.toAscii()))
print(archive_links)
I understand the __init__
acts as a constructor but why is it not setting it to self
? So I need to change it to something like QWebPage.x = self
?