PyQt5 comes with a webkit webbrowser. Webkit is an open source web browser rendering engine that is used by Apple Safari and others. It was used in the older versions of Google Chrome, they have switched to the Blink rendering engine.
QWebView The widget is called QWebView and webpages (HTML content) can be shown through this widget, local or live from the internet.
Methods The QWebView class comes with a lot of methods including:
back (self)
forward (self)
load (self, QUrl url)
reload (self)
#!/usr/bin/python
import PyQt5 from PyQt5.QtCore import QUrl from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtWebKitWidgets import QWebView , QWebPage from PyQt5.QtWebKit import QWebSettings from PyQt5.QtNetwork import * import sys from optparse import OptionParser
classMyBrowser(QWebPage): ''' Settings for the browser.''' defuserAgentForUrl(self, url): ''' Returns a User Agent that will be seen by the website. ''' return"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
Which version of PyQt5 are you using? It doesn't work with PyQt5 5.7.1 an newer versions
Frank•Fri, 09 Jun 2017
Just tested with Python 3.6.1 and PyQt5 5.8.2-2 on Manjaro Linux, it runs fine. PyQt5 has the option to include WebKit, this needs to be done at compilation step of the framework. Sometimes versions of PyQt5 are distributed that don't include WebKit. You could recompile PyQt5 to include WebKit or use a redistributable on another OS like Manjaro.
Leave a Reply:
Which version of PyQt5 are you using?
It doesn't work with PyQt5 5.7.1 an newer versions
Just tested with Python 3.6.1 and PyQt5 5.8.2-2 on Manjaro Linux, it runs fine.
PyQt5 has the option to include WebKit, this needs to be done at compilation step of the framework. Sometimes versions of PyQt5 are distributed that don't include WebKit. You could recompile PyQt5 to include WebKit or use a redistributable on another OS like Manjaro.