2
완전히로드되었을 때 이미지에 페이지 내용을 저장하고 싶지만 출력 래스터가 완전히 렌더링되지 않는 경우가 있습니다.QWebPage의 QImage가 완전히 렌더링되지 않았습니다.
import sys
import signal
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage
app = QApplication(sys.argv)
signal.signal(signal.SIGINT, signal.SIG_DFL)
webpage = QWebPage()
def onLoadFinished(result):
if not result:
print "Request failed"
sys.exit(1)
webpage.setViewportSize(webpage.mainFrame().contentsSize())
image = QImage(webpage.viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
webpage.mainFrame().render(painter)
painter.end()
if os.path.exists("output.png"):
os.remove("output.png")
image.save("output.png")
sys.exit(0) # quit this application
webpage.mainFrame().load(QUrl("file:///page.html"))
webpage.connect(webpage, SIGNAL("loadFinished(bool)"), onLoadFinished)
sys.exit(app.exec_())
페이지에서 자바 스크립트 (onload 함수)를 사용하여 Google지도 (640x640 픽셀)를 얻습니다.
Image http://i56.tinypic.com/15ojg3s.png
페이지로드가 완료된 후 이미지가 Ajax를 사용하여로드되기 때문일 수 있습니다. 이게 유용합니까? http://stackoverflow.com/questions/1302874/how-to-know-when-a-web-page-is-loaded-when-using-qtwebkit? – xioxox