I have a QWebView, which works fine. Then, using code from spynner, I attempt to bind the useragent method to a custom method. This appears to work in spynner (with a QWebPage), but not here. Any help much appreciated. Code:
def customuseragent(url):
print 'called for %s' % url
return 'custom ua'
#inside a class
self.webkit = QtWebKit.QWebView()
self.webkit.page().userAgentForUrl = customuseragent
self.webkit.load(QtCore.QUrl('http://www.whatsmyuseragent.com/'))
I hope this helps...
Your Code
Prerequisite Dependencies
The previous directive allows one to inherit use of the QtWebKit.QWebKit() object and it's methods. But you're missing one more component that allows you to specify the User Agent ("Web browser"). Notice that above I wrote out the signature for the QWebView.load method
It just so happens that you're using QNetworkRequest when you call
So technically the above line is the same as the following:
In order to include the above lines, you need to import:
OR
Connect the Dots
Ok, let's pull it all together now. We understand that QUrl is a QNetworkRequest() object and we can specify the url using QNetworkRequest. The last thing we need to know is how to set the User Agent.
User Agent is set using the setRawHeader(string, string) a method of QNetworkRequest
DONE!
Final Draft
I hope this helped you. I left out a few things because I think you get the fundamentals.