我試圖去設置鏈接,並使用PyQt的拍攝有快照,代碼工作正常的一個網址:PyQt的圖像捕捉錯誤
#!/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_())
但是,因爲它去throuhg一個快照,它只是掛起和犯規繼續下一個快照。這是爲什麼 ?
寫入的代碼將不會運行,因此很難說出你打算如何工作。 –
現在更正。 – Scooby