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()
在上面的示例中,我们获取了捕获的字节,但是如何将其返回到响应将取决于您使用的框架。