[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:20:10 BST 2016


The source code get messed up in last email ,  better code formatting here
http://stackoverflow.com/questions/38071731/print-out-all-the-requested-urls-during-loading-a-web-page






在2016年06月28 18时14分, "redstone-cold"<redstone-cold at 163.com>写道:




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/2558e5d8/attachment-0001.html>


More information about the PyQt mailing list