捕获和转换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();

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