I'm working with PyQt (as a Python beginner).
I need to be able to take screenshots of a website on a headless system.
I was using PhantomJS earlier for another project, but they dropped Flash support in 1.5 and I don't want to rely on a deprecated 1.4 version for my new project.
So I'm using PyQt to do my stuff on my own.
I'm able to take a screenshot of a website with a given url, no problem.
But I keep having the "blue dice" flash plugin icon on flash placeholder (yes, javascript and plugins are activated)
self.settings.setAttribute(QtWebKit.QWebSettings.PluginsEnabled,True)
self.settings.setAttribute(QtWebKit.QWebSettings.JavascriptEnabled,True)
I'm making some test on a Youtube video page, here is an example of my issues:
The second part, that may be related to the first one:
How can I tell PyQt to wait few seconds before taking the screenshot ?
As you can see on the example, images on the right are still unloaded, because they are loaded using javascript and data attribute and in my script, I take the screenshot on the loadFinished signal (onLoad() javascript equivalent)).
My first guess was simply to
time.sleep(2)
Before calling my capture method, but it's not working. I'm assuming that the Webkit loading is also asleep during this sleep time, preventing anything to load on the page.
I tried to create a custom signal, but then I still don't know how to trigger it without sleeping.
My last guess is that I need to thread my application. Am I right?
If you have any hint/script to help me displaying flash content and/or to add a setTimeout like signal, I would be really grateful!
Thanks in advance for you help.
EDIT:
Just a quick edit to add my solution:
timeoutTimer = QTimer()
timeoutTimer.setInterval(3000) # wait for 3secs
timeoutTimer.setSingleShot(True)
timeoutTimer.timeout.connect(theMethodToCallOnTimeout)
About the flash thing: it looks like the flash player is broken on OSX (maybe related to a 32/64 bits issue).
See Question&Answers more detail:
os