Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QWebEngine isn't loading one site



  • Hi,
    First of all, this is my first post here. Hopefully it's in the right category.
    While building my browser for training purposes, I came across a problem which is that there are sites that don't load, such as bet365.com, that is, after loading the page (successful or not, I don't know) QWebEngineView remains white, no content appears, but other sites such as google.com or youtube.com load and have content displayed.

    Screenshot of white window:
    ee51b7ac-eb41-4d62-8c80-75a3ff6b9df6-image.png

    I don't get any errors during code execution.

    The version of PyQt5 is 5.15.4

    I also tried opening bet365.com in the browser that is presented in the Qt example, which uses PySide2, but here too, unfortunately, I got a failure.

    Here is the browser code

    class MyWebEngineUrlRequestInterceptor(QWebEngineUrlRequestInterceptor):
        def __init__(self, parent=None):
            super().__init__(parent)
    
        def interceptRequest(self, info):
            print("interceptRequest")
            print(info.requestUrl())
    
    class MyWebEnginePage(QWebEnginePage):
    
        def acceptNavigationRequest(self, url, _type, isMainFrame):
            print("acceptNavigationRequest")
            print(url)
            return QWebEnginePage.acceptNavigationRequest(self, url, _type, isMainFrame)
    
         def certificateError(self, certificateError):
           print(certificateError.errorDescription(), certificateError.url(), certificateError.isOverridable())
           error = certificateError.error()
    
           return super(MyWebEnginePage, self).certificateError(certificateError)    
    
    class Browser(QMainWindow):
        proxy_type = QNetworkProxy.HttpProxy
        proxy_hostname = 'proxy_hostname'
        proxy_port = 64777
        proxy_username = 'proxy_username'
        proxy_password = 'proxy_username'
    
        def __init__(self, url):
            super().__init__()
            self.searching_url = url
            self.set_auth_proxy()
            self.webEngineView = QWebEngineView()
    
            self.setMinimumSize(1200, 600)
            self.setCentralWidget(self.webEngineView)
    
            interceptor = MyWebEngineUrlRequestInterceptor()
    
            profile = QWebEngineProfile('storage', self.webEngineView)
    
            profile.setRequestInterceptor(interceptor)
    
            url = QUrl(self.searching_url)
            url.setScheme("http")
            url.setHost("www.bet365.com")
            httpReq = QWebEngineHttpRequest()
            httpReq.setUrl(url)
            httpReq.setMethod(QWebEngineHttpRequest.Get)
            httpReq.setHeader(QByteArray(b'Accept'), QByteArray(b'*/*'))
            
            httpReq.setHeader(QByteArray(b'Content-Type'), QByteArray(b'application/json'))
            httpReq.setHeader(QByteArray(b'User-Agent'), QByteArray(b'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'))
    
            print(httpReq.header(QByteArray(b'Host')))
    
            page = MyWebEnginePage(profile, self.webEngineView)
            self.webEngineView.setPage(page)
    
            self.show()
            self.webEngineView.load(httpReq)
    
        def set_auth_proxy(self):
            self.auth_proxy = QNetworkProxy()
            self.auth_proxy.setType(self.proxy_type)
            self.auth_proxy.setHostName(self.proxy_hostname)
            self.auth_proxy.setPort(self.proxy_port)
            self.auth_proxy.setUser(self.proxy_username)
            self.auth_proxy.setPassword(self.proxy_password)
            self.auth_proxy.setApplicationProxy(self.auth_proxy)
    
    
    
    if __name__ == '__main__':
        bet365 = 'https://www.bet365.com'    
        postman = 'http://postman-echo.com/get'
    
        app = QApplication(sys.argv)
        browser = Browser(bet365)
        sys.exit(app.exec_())
    

    Also when I set the Host header like this httpReq.setHeader(QByteArray(b'Host'), QByteArray(b'www.bet365.com')), there is an error with the code ERR_INVALID_ARGUMENT in browser, I thought it was still about the headers when requesting, but no, I have set different headers and no luck.

    What can I do to get bet365 to answer me correctly?


Log in to reply