使用python创建网页的jpg或png图像

时间:2017-02-23 13:03:03

标签: python image

我是新手,我想创建一个带有PyQt4的网页的jpg或png图像,以便您了解我for example something like this

这个脚本非常完美:

import sys
import time
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

width= int(530)
height=int(1060)



class Screenshot(QWebView):

    def __init__(self):
        self.app = QApplication(sys.argv)
        QWebView.__init__(self)
        self._loaded = False
        self.loadFinished.connect(self._loadFinished)

    def capture(self, url, output_file):
        self.load(QUrl(url))
        self.wait_load()

        time.sleep(2)

        # set to webpage size
        frame = self.page().mainFrame()

        self.page().setViewportSize(QSize(width, height,))


        # render image
        image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
        painter = QPainter(image)
        frame.render(painter)
        painter.end()
        print ('Guardada'), output_file
        image.save(output_file)

    def wait_load(self, delay=0):
        # process app events until page loaded
        while not self._loaded:
            self.app.processEvents()
            time.sleep(delay)
        self._loaded = False

    def _loadFinished(self, result):
        self._loaded = True

filename = "capture"


s = Screenshot()
s.capture('http://www.filmaffinity.com/es/main.html', filename+(time.strftime("-%H-%M-%S"))+".png")

这从页面530 px width x上方捕获了我 1060px的高度,这很好,但我希望捕获从网络下方开始并且更加扩展,我的意思是网络的某个区域,

such as this image

如何修改脚本?

由于

0 个答案:

没有答案