{ "cells": [ { "cell_type": "markdown", "id": "f1543948-4781-4f50-849e-1e8b9786b7bb", "metadata": {}, "source": [ "# Splash" ] }, { "cell_type": "markdown", "id": "18805201-1cec-439d-bb09-ac9beba683b2", "metadata": {}, "source": [ "render.json\n", "Return a json-encoded dictionary with information about javascript-rendered webpage. It can include HTML, PNG and other information, based on arguments passed.\n", "\n", "Arguments:\n", "\n", "Same as render.jpeg plus the following ones:\n", "\n", "html : integer : optional\n", "Whether to include HTML in output. Possible values are 1 (include) and 0 (exclude). Default is 0.\n", "png : integer : optional\n", "Whether to include PNG in output. Possible values are 1 (include) and 0 (exclude). Default is 0.\n", "jpeg : integer : optional\n", "Whether to include JPEG in output. Possible values are 1 (include) and 0 (exclude). Default is 0.\n", "iframes : integer : optional\n", "Whether to include information about child frames in output. Possible values are 1 (include) and 0 (exclude). Default is 0.\n", "script : integer : optional\n", "Whether to include the result of the executed javascript final statement in output (see Executing custom Javascript code within page context). Possible values are 1 (include) and 0 (exclude). Default is 0.\n", "console : integer : optional\n", "Whether to include the executed javascript console messages in output. Possible values are 1 (include) and 0 (exclude). Default is 0.\n", "history : integer : optional\n", "Whether to include the history of requests/responses for webpage main frame. Possible values are 1 (include) and 0 (exclude). Default is 0.\n", "\n", "Use it to get HTTP status codes and headers. Only information about “main” requests/responses is returned (i.e. information about related resources like images and AJAX queries is not returned). To get information about all requests and responses use ‘har’ argument.\n", "\n", "har : integer : optional\n", "Whether to include HAR in output. Possible values are 1 (include) and 0 (exclude). Default is 0. If this option is ON the result will contain the same data as render.har provides under ‘har’ key.\n", "\n", "By default, request and response contents are not included. To enable each, use ‘request_body’ and ‘response_body’ options respectively.\n", "\n", "request_body : int : optional\n", "Possible values are 1 and 0. When request_body=1, request content is included in HAR records. Default is request_body=0. This option has no effect when both ‘har’ and ‘history’ are 0.\n", "response_body : int : optiona" ] }, { "cell_type": "code", "execution_count": 27, "id": "8aaec01c-4b87-4949-8787-e9dec8b2e5dd", "metadata": { "execution": { "iopub.execute_input": "2021-10-26T03:50:20.355782Z", "iopub.status.busy": "2021-10-26T03:50:20.355387Z", "iopub.status.idle": "2021-10-26T03:50:20.870039Z", "shell.execute_reply": "2021-10-26T03:50:20.855218Z", "shell.execute_reply.started": "2021-10-26T03:50:20.355743Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(b'{\"url\": \"http://example.com/\", \"requestedUrl\": \"http://example.com/\", \"geome'\n", " b'try\": [0, 0, 1024, 768], \"title\": \"Example Domain\", \"html\": \"'\n", " b'
\\\\nThis domain is for use in illustr'\n", " b'ative examples in documents. You may use this\\\\n domain in literature '\n", " b'without prior coordination or asking for permission.
\\\\n \\\\n<'\n", " b'/div>\\\\n\\\\n\\\\n\", \"history\": [], \"har\": {\"log\": {\"version\": \"1'\n", " b'.2\", \"creator\": {\"name\": \"Splash\", \"version\": \"3.5\"}, \"browser\": {\"name\": \"Q'\n", " b'WebKit\", \"version\": \"602.1\", \"comment\": \"PyQt 5.14.2, Qt 5.14.1\"}, \"entries\"'\n", " b': [], \"pages\": [{\"id\": \"1\", \"title\": \"Example Domain\", \"startedDateTime\": \"2'\n", " b'021-10-26T03:50:20.767475Z\", \"pageTimings\": {\"onContentLoad\": 4, \"onLoad\": 2'\n", " b'3, \"_onStarted\": 1, \"_onPrepareStart\": 23, \"_onIframesRendered\": 24}}]}}}')\n" ] } ], "source": [ "import json\n", "import pprint\n", "\n", "import requests\n", "\n", "# script = \"\"\"\n", "# splash:go(args.url)\n", "# return splash:png()\n", "# \"\"\"\n", "\n", "\n", "resp = requests.post(\n", " \"https://kong.donavanaldrich.com/splash\",\n", " json={\n", " \"url\": \"http://example.com\",\n", " \"history\": 1,\n", " \"html\": 1,\n", " \"request_body\": 1,\n", " \"har\": 1,\n", " },\n", ")\n", "png_data = resp.content\n", "\n", "pp = pprint.PrettyPrinter(indent=4, sort_dicts=True)\n", "pp.pprint(png_data)" ] }, { "cell_type": "code", "execution_count": 44, "id": "1630de92-c015-43a3-b747-9d29ca5afba2", "metadata": { "execution": { "iopub.execute_input": "2021-10-26T04:36:51.911804Z", "iopub.status.busy": "2021-10-26T04:36:51.911422Z", "iopub.status.idle": "2021-10-26T04:36:55.323679Z", "shell.execute_reply": "2021-10-26T04:36:55.322189Z", "shell.execute_reply.started": "2021-10-26T04:36:51.911765Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[34mHTTP\u001b[39;49;00m/\u001b[34m1.1\u001b[39;49;00m \u001b[34m200\u001b[39;49;00m \u001b[36mOK\u001b[39;49;00m\n", "\u001b[36mContent-Type\u001b[39;49;00m: application/json\n", "\u001b[36mDate\u001b[39;49;00m: Tue, 26 Oct 2021 04:36:54 GMT\n", "\u001b[36mServer\u001b[39;49;00m: TwistedWeb/19.7.0\n", "\u001b[36mTransfer-Encoding\u001b[39;49;00m: chunked\n", "\u001b[36mVia\u001b[39;49;00m: kong/2.6.0\n", "\u001b[36mX-Cache-Status\u001b[39;49;00m: Bypass\n", "\u001b[36mX-Frame-Options\u001b[39;49;00m: DENY\n", "\u001b[36mX-Kong-Proxy-Latency\u001b[39;49;00m: 5\n", "\u001b[36mX-Kong-Upstream-Latency\u001b[39;49;00m: 91\n", "\n", "{\n", " \u001b[94m\"geometry\"\u001b[39;49;00m: [\n", " \u001b[34m0\u001b[39;49;00m,\n", " \u001b[34m0\u001b[39;49;00m,\n", " \u001b[34m1024\u001b[39;49;00m,\n", " \u001b[34m768\u001b[39;49;00m\n", " ],\n", " \u001b[94m\"har\"\u001b[39;49;00m: {\n", " \u001b[94m\"log\"\u001b[39;49;00m: {\n", " \u001b[94m\"browser\"\u001b[39;49;00m: {\n", " \u001b[94m\"comment\"\u001b[39;49;00m: \u001b[33m\"PyQt 5.14.2, Qt 5.14.1\"\u001b[39;49;00m,\n", " \u001b[94m\"name\"\u001b[39;49;00m: \u001b[33m\"QWebKit\"\u001b[39;49;00m,\n", " \u001b[94m\"version\"\u001b[39;49;00m: \u001b[33m\"602.1\"\u001b[39;49;00m\n", " },\n", " \u001b[94m\"creator\"\u001b[39;49;00m: {\n", " \u001b[94m\"name\"\u001b[39;49;00m: \u001b[33m\"Splash\"\u001b[39;49;00m,\n", " \u001b[94m\"version\"\u001b[39;49;00m: \u001b[33m\"3.5\"\u001b[39;49;00m\n", " },\n", " \u001b[94m\"entries\"\u001b[39;49;00m: [],\n", " \u001b[94m\"pages\"\u001b[39;49;00m: [\n", " {\n", " \u001b[94m\"id\"\u001b[39;49;00m: \u001b[33m\"1\"\u001b[39;49;00m,\n", " \u001b[94m\"pageTimings\"\u001b[39;49;00m: {\n", " \u001b[94m\"_onIframesRendered\"\u001b[39;49;00m: \u001b[34m84\u001b[39;49;00m,\n", " \u001b[94m\"_onPngRendered\"\u001b[39;49;00m: \u001b[34m83\u001b[39;49;00m,\n", " \u001b[94m\"_onPrepareStart\"\u001b[39;49;00m: \u001b[34m12\u001b[39;49;00m,\n", " \u001b[94m\"_onScreenshotPrepared\"\u001b[39;49;00m: \u001b[34m25\u001b[39;49;00m,\n", " \u001b[94m\"_onStarted\"\u001b[39;49;00m: \u001b[34m1\u001b[39;49;00m,\n", " \u001b[94m\"onContentLoad\"\u001b[39;49;00m: \u001b[34m3\u001b[39;49;00m,\n", " \u001b[94m\"onLoad\"\u001b[39;49;00m: \u001b[34m12\u001b[39;49;00m\n", " },\n", " \u001b[94m\"startedDateTime\"\u001b[39;49;00m: \u001b[33m\"2021-10-26T04:36:54.558005Z\"\u001b[39;49;00m,\n", " \u001b[94m\"title\"\u001b[39;49;00m: \u001b[33m\"Example Domain\"\u001b[39;49;00m\n", " }\n", " ],\n", " \u001b[94m\"version\"\u001b[39;49;00m: \u001b[33m\"1.2\"\u001b[39;49;00m\n", " }\n", " },\n", " \u001b[94m\"history\"\u001b[39;49;00m: [],\n", " \u001b[94m\"html\"\u001b[39;49;00m: \u001b[33m\"\\nThis domain is for use in illustrative examples in documents. You may use this\\n domain in literature without prior coordination or asking for permission.
\\n \\n