有没有办法使用驻留在我服务器上的指定HTML / Javascript页面的PIL截取屏幕截图?
我想编写一个脚本,它将更改该HTML页面上的一些参数,然后让PIL截取它的截图。
有什么想法吗?这些例子将得到真正的赞赏。
答案 0 :(得分:2)
你绝对必须使用PIL吗?如果没有,你可以使用具有内置Webkit控件的PyQT获得你想要的东西。
有关将html + css转换为PDF而不使用单独浏览器的示例,请参阅http://notes.alexdong.com/xhtml-to-pdf-using-pyqt4-webkit-and-headless。代码很短,所以我在下面复制了它。
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("http://www.google.com"))
#web.show()
printer = QPrinter()
printer.setPageSize(QPrinter.A4)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName("file.pdf")
def convertIt():
web.print_(printer)
print "Pdf generated"
QApplication.exit()
QObject.connect(web, SIGNAL("loadFinished(bool)"), convertIt)
sys.exit(app.exec_())