GrabzIt Python API 具有許多高級功能,包括使應用程序能夠檢查現有屏幕截圖的狀態,並允許由應用程序設置GrabzIt將使用的cookie。
對於要檢查屏幕快照狀態的應用程序,請使用GetStatus方法。 這將返回一個狀態對象,該狀態對象指示捕獲是否仍在處理中,是否有錯誤消息,是否已緩存或已過期。
from GrabzIt import GrabzItClient grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret") status = grabzIt.GetStatus(screenShotId) if status.processing: # screenshot has not yet been processed if status.cached: # screenshot is still cached by GrabzIt if status.expired: # screenshot is no longer on GrabzIt # Perhaps output status message? raise Exception(status.Message)
許多網站通過Cookie控製網頁功能。 GrabzIt允許您通過以下方式設置自己的開發人員定義的cookie。
from GrabzIt import GrabzItClient grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret") # gets an array of cookies for google.com cookies = grabzIt.GetCookies("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功能的很好概述,但cookie方法確實具有更多參數,如 客戶文件.
雖然建議將捕獲的內容使用前下載到Web服務器。 可以在用戶瀏覽器中顯示任何類型的捕獲,而無需先將其下載到Web服務器上。
為此,捕獲完成後,您可以發送由 SaveTo 方法 響應以及 正確的啞劇類型.
from GrabzIt import GrabzItClient grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret") grabzIt.URLToImage("https://www.tesla.com") capture = grabzIt.SaveTo()
在上面的示例中,我們獲取了捕獲的字節,但是如何將其返回到響應將取決於您使用的框架。