5

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

4

8 回答 8

6

有很多方法:

  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

于 2009-09-28T18:40:37.327 回答
3

对我来说最好的解决方案:使用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 不会以这种方式工作,因为它是无头的。

该死的容易!

于 2014-06-29T11:08:56.717 回答
3

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

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

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

http://www.browsercam.com

http://webthumb.bluga.net/home

仅举几例。

于 2009-09-28T18:36:56.820 回答
2

Litmus是这类事情的绝佳在线资源;您可以提交一个 URL 并让它在最新的浏览器上截取整页屏幕截图。如果您获得付费订阅或在周末使用它,您将可以在其所有 22 种浏览器上进行测试,而不仅仅是最新的。我一直在使用这个网站,我认为它非常棒。

BrowserShots也很棒,它支持更多的浏览器,但根据我的经验,它也慢了很多。不过,如果您需要测试一些 Litmus 不需要的浏览器,则可以使用它。

于 2009-09-28T18:34:28.750 回答
0

我发现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
于 2012-05-02T05:37:58.547 回答
0

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

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

于 2009-09-28T18:40:14.007 回答
0

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

于 2009-09-28T19:37:24.653 回答
0

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

  • 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

于 2015-03-17T22:59:18.797 回答