我正在运行 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()
虽然这个网站不工作 :(,我想知道是否可以用 this website 来做,如果可以,怎么做?如果不可能,还有其他选择吗?
最佳答案
有一个名为 webkit2png 的包,您可以使用它,它位于:here
有关 this blog post 的更多信息
博文示例(复制到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_())
关于python - 网站图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5266830/