Webをキャプチャして変換するツール

Pythonの高度なスクリーンショット機能

Python API

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)について

多くのWebサイトは、Cookieを使用してWebページの機能を制御しています。 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 方法 応答とともに 正しいMIMEタイプ.

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()

上記の例では、キャプチャのバイトを取得していますが、応答にどのように返されるかは、使用しているフレームワークによって異なります。