我正在尝试使用 PyQt 转到一组 url 并捕获那里的快照,该代码适用于一个 url:
#!/usr/bin/env python
import sys, itertools
import signal
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage
urls = "http://www.gouvernement.fr/", "http://www.google.com/"
outputs = "output1.png", "output2.png"
#for url in urls: #and output in ouputs:
for url, output in itertools.izip(urls, outputs):
def onLoadFinished(result):
if not result:
print "Request failed"
sys.exit(1)
# Set the size of the (virtual) browser window
webpage.setViewportSize(webpage.mainFrame().contentsSize())
# Paint this frame into an image
image = QImage(webpage.viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
webpage.mainFrame().render(painter)
painter.end()
image.save(output)
print ".png image successfully saved"
#sys.exit(0)
app = QApplication(sys.argv)
signal.signal(signal.SIGINT, signal.SIG_DFL)
webpage = QWebPage()
webpage.connect(webpage, SIGNAL("loadFinished(bool)"), onLoadFinished)
webpage.mainFrame().load(QUrl(url))
sys.exit(app.exec_())
但是当它通过一个快照时,它只是挂起并且不会继续进行下一个快照。这是为什么 ?