GrabzItのAPIは非常にカスタマイズ可能です。 2つの便利な機能は、 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? } });
多くのWebサイト機能は、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 方法 応答とともに 正しいMIMEタイプ。 この例 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(); });