GrabzIt的API是非常可定制的。 两个有用的功能是 GrabzIt Node.js API 在创建屏幕截图和捕获内容时检查现有屏幕截图的状态并自定义GrabzIt发送的cookie。
要检查屏幕截图或捕获的状态,请使用 get_status 方法,这将返回一个状态对象,该状态对象指示捕获是否仍在处理中,是否已缓存或已过期。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); client.get_status(screenShotId, function(error, status){ 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? } });
Cookie可以控制许多网站功能。 GrabzIt允许您使用如下所示的cookie方法来设置自己的自定义cookie。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); //gets an array of cookies for google.com client.get_cookies("google.com", function(error, cookies){ }); //sets a cookie for the google.com domain client.set_cookie("MyCookie", "google.com", {"value":"Any Value You Like"}); //deletes the previously set cookie client.delete_cookie("MyCookie", "google.com");
虽然建议将捕获的内容使用前下载到Web服务器。 可以在用户浏览器中显示任何类型的捕获,而无需先将其下载到Web服务器上。
为此,捕获完成后,您可以发送由捕获的oncomplete函数返回的捕获字节 save_to 方法 响应以及 正确的哑剧类型。 这方面的一个例子 url_to_image
方法如下所示,但可以与任何转换方法一起使用。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); client.url_to_image("https://www.tesla.com"); client.save_to(null, function(error, data){ response.writeHead(200, {"Content-Type":"image/jpeg"}); response.write(data); response.end(); });