python 如何使用服务器端脚本生成网页的屏幕截图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/713938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I generate a screenshot of a webpage using a server-side script?
提问by Colargol
I need a server-side script (PHP, Python) to capture a webpage to a PNG, JPG, Tiff, GIF image and resize them to a thumbnail.
我需要一个服务器端脚本(PHP、Python)来将网页捕获为 PNG、JPG、Tiff、GIF 图像并将它们调整为缩略图。
What is the best way to accomplish this?
实现这一目标的最佳方法是什么?
See also:
也可以看看:
采纳答案by Can Berk Güder
You can probably write something similar to webkit2png, unless your server already runs Mac OS X.
您可能可以编写类似于webkit2png 的内容,除非您的服务器已经运行 Mac OS X。
UPDATE:I just saw the link to its Linux equivalent: khtml2png
更新:我刚刚看到了它的 Linux 等效链接:khtml2png
See also:
也可以看看:
回答by ólafur Waage
What needs to happen is for a program to render the page and then take an image of the page. This is a very slow and heavy process but it can be done in PHP on Windows.
需要发生的是让程序呈现页面,然后拍摄页面的图像。这是一个非常缓慢和繁重的过程,但它可以在 Windows 上的 PHP 中完成。
Also check the comments in the documentation article.
还要检查文档文章中的注释。
For python I'd recommend reading this article. It highlights some of the solutions.
对于 python,我建议阅读这篇文章。它重点介绍了一些解决方案。
There are services you can also call (via some API) that will return you an image. But usually they cost (WebShotsfor example)
您还可以调用(通过某些 API)一些服务来返回图像。但通常它们会花费(例如WebShots)
回答by Aziz
You'll need to:
你需要:
- read the webpage and all the its multimedia content (images, flash, etc)
- utilize a browser rendering engine to render the webpage
- take a screenshot and save it as image
- 阅读网页及其所有多媒体内容(图像、Flash 等)
- 利用浏览器渲染引擎来渲染网页
- 截取屏幕截图并将其保存为图像
first and third steps are easy, the second step is more challenging ;)
第一步和第三步很容易,第二步更具挑战性;)
回答by Frank Vielma
If you are using php, you could use imagegrabscreen (PHP 5 >= 5.2.2). Imagegrabscreen: captures the whole screen.
如果您使用的是 php,则可以使用 imagegrabscreen (PHP 5 >= 5.2.2)。Imagegrabscreen:捕获整个屏幕。