捕獲和轉換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類型,但是如何將其返回給響應將取決於您使用的框架。