如何拍摄网站的全屏截图

我需要通过URL获取网站的全屏镜头,是否有任何PHP程序或服务,如果没有,是否有任何Java程序用于此目的?

有很多方法:

  1. 使用http://khtml2png.sourceforge.net/index.php?page=faq

  2. 使用带有一些绑定的webkit引擎: http : //www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit /

  3. 在批处理模式下使用mozilla引擎: http : //www.chimeric.de/blog/2007/1018_automated_screenshots_using_bash_firefox_and_imagemagick

您需要有一个特殊版本的浏览器,以便 PHP或Java处理页面 “呈现”页面。

在ping运行Windows,OSX或Linux窗口管理器的服务器之后,您最有可能需要设置一些自定义自动化脚本来命中URL。

有服务可以为你做屏幕截图。

http://www.browsercam.com

http://webthumb.bluga.net/home

仅举几例。

Litmus是这类事物的绝佳在线资源; 您可以提交一个URL,并在最新的浏览器上获取整页截图。 如果您获得付费订阅或在周末使用它,您将可以访问所有22个浏览器而不是最近的浏览器。 我一直都在使用这个网站,我认为这是惊人的。

BrowserShots也很棒,它支持更多的浏览器,但根据我的经验,它也会慢得多。 不过,如果你需要测试一些浏览器,那么最好使用Litmus。

对我来说最好的解决方案:使用selenium webdriver并截取屏幕截图可以像这样简单:

import java.io.File; import java.net.URL; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.Augmenter; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class Testing { public void myTest() throws Exception { WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox()); driver.get("http://www.google.com"); // RemoteWebDriver does not implement the TakesScreenshot class // if the driver does have the Capabilities to take a screenshot // then Augmenter will add the TakesScreenshot methods to the instance WebDriver augmentedDriver = new Augmenter().augment(driver); File screenshot = ((TakesScreenshot)augmentedDriver). getScreenshotAs(OutputType.FILE); } } 

别忘了使用FireFoxDriver。 HtmlUnitDriver不会以这种方式工作,因为它无头。

很容易!

如果您有专用服务器,也可以自己动手。 我们的想法是以全屏模式启动X Server和浏览器,拍摄并将其保存到图像文件中。

根据您的使用情况(偶尔或密集),您可以调整过程(即不会每次都杀死X等等)以使其更快。

从问题是否要以编程方式或手动方式进行此操作尚不清楚。 如果手动:Firefox有一个很棒的插件叫做Abduction! 将页面呈现为图像。 否则,凯恩的答案几乎涵盖了它。

我发现CutyCapt是最容易截屏的解决方案,它可以在Windows和Linux中运行。

在Windows中安装:

只需下载文件并执行即可。

安装在debian中:

 apt-get install cutycapt xvfb 

和运行:

 xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/cutycapt --url=http://www.google.com --out=/home/screenshots/screenshot_name.png 

尝试无头浏览器 。 其中任何一个都应该这样做:

  • PhantomJS – >使用’Webkit’布局引擎(Safari / Chromium)
  • TrifleJS – >使用’Trident’布局引擎(Internet Explorer)
  • SlimerJS – >使用’Gecko’布局引擎(Firefox)

您可以使用以下javascript代码截取屏幕截图(保存到文件renderpage.js ):

 var page = require('webpage').create(); page.open('http://en.wikipedia.org', function() { page.render('wikipedia.png'); }); 

然后通过命令行执行:

 > phantomjs.exe renderpage.js 

这将使用您的屏幕截图创建一个文件wikipedia.png