使用python创建网页的jpg或png图像
我是新手,我想创建一个带有PyQt4的网页的jpg或png图像,以便您理解我 这个脚本非常完美:使用python创建网页的jpg或png图像,python,image,Python,Image,我是新手,我想创建一个带有PyQt4的网页的jpg或png图像,以便您理解我 这个脚本非常完美: 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__(sel
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")
这是我从530px宽x的页面上看到的
1060px的高度,这很好,但我希望捕获从网络下方开始,并进一步扩展,我指的是网络的某个区域
如何修改脚本
谢谢我想使用PyQt4的可能副本,谢谢好的,你说得对吗,对不起,但是我需要一些修改,这些修改在我想使用PyQt4的可能副本中没有详细说明,谢谢好的,你说得对吗,对不起,我需要一些修改,这些修改在那篇文章中没有详细说明