2023-10-30 08:00:01

网站截图

有什么方法可以用PHP截图一个网站,然后保存到一个文件?


当前回答

这完全取决于你想如何截屏。

你可以通过PHP,使用webservice来获取图像

grabz。它有一个webservice来做这件事,这里有一篇文章展示了一个使用该服务的简单示例。

http://www.phpbuilder.com/articles/news-reviews/miscellaneous/capture-screenshots-in-php-with-grabzit-120524022959.html

其他回答

不直接。像Selenium这样的软件有这样的特性,可以用PHP控制,但有其他依赖(比如在你想要截图的浏览器的计算机上运行基于java的服务器)

你可以使用剪贴画。

KWHTML已弃用,像旧浏览器一样显示页面。

Cutycapt保存网页的大多数图像格式(jpg,png..)下载它从你的突触,它比wkhtmltopdf工作得更好

我最后按照@boksiora的建议使用microweber/screen进行设置。 最初当尝试这里提到的链接时,我得到了什么:

Please download this script from here https://github.com/microweber/screen

我用的是Linux。所以如果你想运行它,你可以根据你的环境调整我的步进。 下面是我在shell上DOCUMENT_ROOT文件夹上做的步骤:

$ sudo wget https://github.com/microweber/screen/archive/master.zip
$ sudo unzip master.zip
$ sudo mv screen-master screen
$ sudo chmod +x screen/bin/phantomjs
$ sudo yum install fontconfig
$ sudo yum install freetype*
$ cd screen
$ sudo curl -sS https://getcomposer.org/installer | php
$ sudo php composer.phar update
$ cd ..
$ sudo chown -R apache screen
$ sudo chgrp -R www screen
$ sudo service httpd restart

将浏览器指向screen/demo/shot.php?url=google.com。当你看到屏幕截图时,你就完成了。更多高级设置的讨论可在这里和这里。

如果你不想使用任何第三方工具,我遇到了一个简单的解决方案,那就是使用谷歌页面洞察api。

只需要调用它的api与params截图=true。

https://www.googleapis.com/pagespeedonline/v1/runPagespeed?
url=https://stackoverflow.com/&key={your_api_key}&screenshot=true

对于移动站点视图传递&策略=移动参数,

https://www.googleapis.com/pagespeedonline/v1/runPagespeed?
url=http://stackoverflow.com/&key={your_api_key}&screenshot=true&strategy=mobile

演示。