网站图像

Ale*_*ex 5 python image python-3.x

我正在运行Python 3.1,你会称我为高级新手:)

我的问题很简单:我正在尝试制作一个简单的程序,要求用户提供一个URL(或多个URL),然后进入网站并截取整个页面的截图,而不仅仅是可以在浏览器没有完全滚动).

它听起来更简单,我想在网络上使用现有平台,类似于:

import subprocess
MYFILENAME = "google_screen"
MYURL = "www.google.com"
subprocess.Popen(['wget', '-O', MYFILENAME+'.png', 'http://images.websnapr.com/?url='+MYURL+'&size=s&nocache=82']).wait()
Run Code Online (Sandbox Code Playgroud)

虽然这个网站不起作用:(,我想知道是否可以用这个网站做到这一点,如果是这样,怎么样?如果不可能,还有其他选择吗?

scl*_*son 3

有一个名为 webkit2png 的包,您可以使用它,它位于:这里

有关此博文的更多信息

博客文章中的示例(复制到 SO 进行保存,如果有问题,请阅读博客文章以了解它):

#!/usr/bin/env python
import sys
import signal

from PyQt4.QtCore import *
from PyQt 4.QtGui import *
from PyQt4.QtWebKit import QWebPage

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("output2.png")
    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("http://www.google.com"))

sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

编辑:链接到pyqt4下载页面