[PyQt] Different QWebView objects gives identical output for same urls
Florian Bruhin
me at the-compiler.org
Wed Feb 11 14:41:24 GMT 2015
* Герасимов Михаил <Gerasimov-M-N at yandex.ru> [2015-02-11 17:04:06 +0300]:
> I found that if we load one url with different QWebView objects parallely,
> we will have identical output: only one of this QWebView will make real
> request. Here is example:
>
> ...
>
> It was surprising. How can we get "fair", unique output for each QWebView
> object, If url is the same?
Weird.
First I suspected an issue with late binding in the closure:
http://docs.python-guide.org/en/latest/writing/gotchas/#late-binding-closures
However this doesn't seem to be the case here... I then simplified the
script a bit and added some prints:
import functools
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebView
def on_ready(v):
print(v)
print(v.page())
print(v.page().mainFrame())
print(v.page().mainFrame().documentElement())
print(v.page().mainFrame().documentElement().toPlainText())
if __name__ == '__main__':
app = QApplication([])
# This url outputs random number:
url = QUrl('https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new')
view = QWebView()
view.load(url)
view.loadFinished.connect(functools.partial(on_ready, view))
view2 = QWebView()
view2.load(url)
view2.loadFinished.connect(functools.partial(on_ready, view2))
view2.loadFinished.connect(app.quit)
app.exec_()
Output:
<PyQt5.QtWebKitWidgets.QWebView object at 0x7f2c159c98b8>
<PyQt5.QtWebKitWidgets.QWebPage object at 0x7f2c159c9948>
<PyQt5.QtWebKitWidgets.QWebFrame object at 0x7f2c159c99d8>
<PyQt5.QtWebKit.QWebElement object at 0x7f2c109630b8>
66
<PyQt5.QtWebKitWidgets.QWebView object at 0x7f2c159c9828>
<PyQt5.QtWebKitWidgets.QWebPage object at 0x7f2c159c99d8>
<PyQt5.QtWebKitWidgets.QWebFrame object at 0x7f2c159c9948>
<PyQt5.QtWebKit.QWebElement object at 0x7f2c109630b8>
66
Note there are dedicated view/page/frame elements, but the
documentElement is the same in both cases. I can't figure out why that
is though...
Florian
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150211/f4383c63/attachment.sig>
More information about the PyQt
mailing list