[PyQt] print out all the requested URLs during loading a web page by Qt WebEngine
redstone-cold
redstone-cold at 163.com
Tue Jun 28 11:14:06 BST 2016
In my project, there is some need to get a certain requested URL during loading a web page,
I think get the URL by Qt WebEngine is a good solution. I started by trying to use the code below to print out all the requested URLs during loading a web page, but it didn't work , so what's wrong here ? Any good solutions ?
import sysimport osfromPyQt5.QtWidgetsimportQApplicationfromPyQt5.QtWebEngineWidgetsimport*fromPyQt5.QtWebEngineCoreimport*fromPyQt5.QtCoreimportQUrlclassWebEngineUrlRequestInterceptor(QWebEngineUrlRequestInterceptor):
def __init__(self, parent=None):
super().__init__(parent)
def interceptRequest(self, info):
print(info.requestUrl())if __name__ =='__main__':
app =QApplication(sys.argv)
profile =QWebEngineProfile()
profile.setRequestInterceptor(WebEngineUrlRequestInterceptor())
page =QWebEnginePage(profile)
page.setUrl(QUrl(
"http://music.163.com/"))
view =QWebEngineView()
view.setPage(page)
view.resize(1024,600)
view.show()
sys.exit(app.exec_())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160628/8a5e0b23/attachment-0001.html>
More information about the PyQt
mailing list