pythonpyqtpyqt4recaptchaqwebview

How to make Recaptcha work with QWebView


I'm trying to get PyQt4 to view a web-page that requires a captcha to work, but it says that the browser is unsupported. Here is a screenshot of the message:

screenshot

Is there any way to fix this?


Solution

  • I was able to get this to work by modifying the user-agent string to include one of the supported browsers:

    import sys
    from PyQt4 import QtCore, QtGui, QtWebKit
    
    class WebPage(QtWebKit.QWebPage):
        def userAgentForUrl(self, url):
            return super(WebPage, self).userAgentForUrl(url) + ' Chrome'
    
    class Window(QtWebKit.QWebView):
        def __init__(self):
            super(Window, self).__init__()
            self.setPage(WebPage(self))
            self.load(QtCore.QUrl('https://www.google.com/recaptcha/api2/demo'))
    
    if __name__ == '__main__':
    
        app = QtGui.QApplication(sys.argv)
        window = Window()
        window.setGeometry(600, 100, 600, 900)
        window.show()
        sys.exit(app.exec_())