捕獲和轉換Web的工具

Ruby的高級屏幕截圖功能

Ruby API

以及標準的屏幕截圖功能 GrabzIt的Ruby API 允許開發人員 int通過啟用應用程序掛鉤來與GrabzIt緊密協作 into GrabzIt服務的內部工作原理,例如,檢查現有屏幕截圖的狀態並設置GrabzIt在捕獲Web內容時將使用的cookie。

屏幕截圖狀態

應用程序可能需要檢查捕獲的狀態,這是 get_status 方法非常有用,它返回一個對象,該對象指示捕獲是否仍在處理,緩存或已過期,並返回與捕獲相關的任何錯誤消息。

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

status = grabzItClient.get_status(screenShotId)

if status.processing
    #screenshot has not yet been processed
end

if status.cached
    #screenshot is still cached by GrabzIt
end

if status.expired
    #screenshot is no longer on GrabzIt
    #Perhaps output status message?
    raise status.message
end

Cookies

幾乎所有網站都通過Cookie控制功能。 為了使您能夠更改目標網站GrabzIt的網站功能,它公開了以下cookie方法,有關可用於這些方法的參數的更多信息,請閱讀 客戶文件.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

#gets an array of cookies for google.com
cookies = grabzItClient.get_cookies("google.com")

#sets a cookie for the google.com domain
grabzItClient.set_cookie("MyCookie", "google.com", "Any Value You Like")

#deletes the previously set cookie
grabzItClient.delete_cookie("MyCookie", "google.com")

顯示捕獲而不下載

建議在使用捕獲文件之前將其下載到Web服務器。 但是,可以在用戶瀏覽器中顯示任何類型的捕獲,而無需先將其下載到Web服務器上。

為此,捕獲完成後,您可以發送由 save_to 方法 響應以及 正確的啞劇類型.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

grabzItClient.url_to_image("https://www.tesla.com")	
capture = grabzItClient.save_to();

在上面的示例中,我們獲取了捕獲的字節,但是如何將其返回到響應將取決於您使用的框架。