捕获和转换Web的工具

Java的高级屏幕截图功能

Java API

除了基本的屏幕截图功能 GrabzIt的Java API 可以检查现有屏幕快照的状态,并允许自定义GrabzIt创建捕获时应使用的cookie。

屏幕截图状态

有时,应用程序可能需要检查屏幕快照的状态,以查看其是否已被使用或检查其是否仍在缓存中。

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

Status status = grabzIt.GetStatus(screenShotId);

if (status.isProcessing())
{
    // screenshot has not yet been processed
}

if (status.isCached())
{
    // screenshot is still cached by GrabzIt
}

if (status.isExpired())
{
    // screenshot is no longer on GrabzIt
    // Perhaps output status message?
}

Cookies

网站通常使用Cookie来控制功能,例如确定用户是否 登录。 使用以下cookie方法,您可以设置自己的自定义cookie。

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

// gets an array of cookies for google.com
Cookie[] cookies = grabzIt.Cookies("google.com");

// sets a cookie for the google.com domain
grabzIt.SetCookie("MyCookie", "google.com", "Any Value You Like");

// deletes the previously set cookie
grabzIt.DeleteCookie("MyCookie", "google.com");

上面的删除cookie方法将删除存储在GrabzIt上具有相同名称和域的所有cookie。

显示捕获而不下载

虽然建议将捕获的内容使用前下载到Web服务器。 可以在用户浏览器中显示任何类型的捕获,而无需先将其下载到Web服务器上。

捕获完成后,您可以发送由 SaveTo 方法 响应以及 正确的哑剧类型.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

grabzIt.URLToImage("https://www.tesla.com");
GrabzItFile capture = grabzIt.SaveTo();

if (capture != null)
{ 
    String mimeType = "image/jpeg";
    capture.getBytes();
}

在上面的示例中,我们获取了捕获的字节和MIME类型,但是如何将其返回给响应将取决于您使用的框架。