Strona główna / HTML i zrzuty ekranu: kolejność działań

HTML i zrzuty ekranu: kolejność działań

Pobierz kopie HTML i zrzuty ekranu zapisane przez monitoring. Sprawdź dostępność plików i przejdź przez kolejne kroki pobierania.

Na tej stronie

Te metody dotyczą monitorowania zmian. Pobierają zapisany HTML lub zrzut PNG strony z wybranego sprawdzenia. Są to kopie z raportu, a nie aktualna strona.

Najpierw pobierz wiersze z include_state=true. Skopiuj url_md5 strony i sprawdź pola state.files poniżej. Przy pobieraniu użyj tego samego projektu, raportu i strony. Dla zrzutów wybierz device=desktop lub device=mobile; domyślnie desktop.

Parametr Opis
state.files.html_available Dostępność kopii HTML
state.files.screenshot_desktop_available Dostępność zrzutu dla komputera
state.files.screenshot_mobile_available Dostępność zrzutu mobilnego
state.files.*_expires_at / state.files.*_expires_in_days Data wygaśnięcia i liczba pozostałych dni dla pliku. Wartości mogą być nieobecne, gdy okres przechowywania jest nieznany.

Okres przechowywania dotyczy wybranego sprawdzenia. Zmiana ustawień nie zmienia okresu opłaconych plików. 404 file_not_available oznacza brak pliku, wygaśnięcie okresu lub rozmiar ponad 10 MB. HTML jest zwracany jako text/html, a zrzuty jako image/png.

  • Uprawnienie do HTML: diff-htmlfiles:read.
  • Uprawnienie do zrzutów ekranu: diff-screenshot:read.

GET /public-api/v1/diff-projects/{diff_project_id}/reports/{report_id}/pages/{url_md5}/html

Pobiera HTML strony zapisany dla wybranego raportu.

GET /public-api/v1/diff-projects/{diff_project_id}/reports/{report_id}/pages/{url_md5}/screenshot

Pobiera zrzut ekranu. Zapytanie: device=desktop lub device=mobile.

Pobierz HTML

curl

curl --fail-with-body --silent --show-error --location \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Accept: text/html' \
  --output 'page.html' \
  'https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html'

JavaScript

const { writeFile } = require("node:fs/promises")

async function main () {
  const response = await fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html", {
    method: "GET",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "text/html",
    },
    signal: AbortSignal.timeout(30_000),
  })

  if (!response.ok) {
    const responseText = await response.text()
    throw new Error(`HTTP ${response.status}: ${responseText}`)
  }

  await writeFile("page.html", Buffer.from(await response.arrayBuffer()))
}

main().catch(error => {
  console.error(error)
  process.exitCode = 1
})

Python

import json
from pathlib import Path
import requests

url = "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Accept": "text/html",
}

response = requests.request(
    "GET",
    url,
    headers=headers,
    timeout=30,
)
response.raise_for_status()
Path("page.html").write_bytes(response.content)

PHP

<?php

$curl = curl_init('https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html');

if ($curl === false) {
    throw new RuntimeException('Unable to initialize cURL');
}

curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer YOUR_API_KEY',
        'Accept: text/html',
    ],
]);

$response = curl_exec($curl);

if ($response === false) {
    $message = curl_error($curl);
    curl_close($curl);
    throw new RuntimeException('Network error: ' . $message);
}

$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE) ?: '';
curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException("HTTP $status: $response");
}

if (file_put_contents('page.html', $response) === false) {
    throw new RuntimeException('Unable to save response file');
}

Go

package main

import (
	"context"
	"fmt"
	"io"
	"net/http"
	"os"
	"time"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Second)
	defer cancel()

	request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html", nil)
	if err != nil {
		panic(err)
	}

	request.Header.Set("Authorization", "Bearer YOUR_API_KEY")
	request.Header.Set("Accept", "text/html")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusMultipleChoices {
		errorBody, readErr := io.ReadAll(response.Body)
		if readErr != nil {
			panic(readErr)
		}
		panic(fmt.Sprintf("HTTP %d: %s", response.StatusCode, errorBody))
	}

	output, err := os.Create("page.html")
	if err != nil {
		panic(err)
	}

	if _, err := io.Copy(output, response.Body); err != nil {
		output.Close()
		panic(err)
	}
	if err := output.Close(); err != nil {
		panic(err)
	}
}

Google Apps Script

function callLabrikaPublicAPI() {
  const response = UrlFetchApp.fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html", {
    method: "get",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "text/html",
    },
    followRedirects: false,
    muteHttpExceptions: true,
  });
  const status = response.getResponseCode();
  if (status < 200 || status >= 300) {
    throw new Error('HTTP ' + status + ': ' + response.getContentText());
  }
  DriveApp.createFile(response.getBlob().setName("page.html"));
}

Pobierz PNG

curl

curl --fail-with-body --silent --show-error --location \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Accept: image/png' \
  --output 'screenshot.png' \
  'https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop'

JavaScript

const { writeFile } = require("node:fs/promises")

async function main () {
  const response = await fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop", {
    method: "GET",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "image/png",
    },
    signal: AbortSignal.timeout(30_000),
  })

  if (!response.ok) {
    const responseText = await response.text()
    throw new Error(`HTTP ${response.status}: ${responseText}`)
  }

  await writeFile("screenshot.png", Buffer.from(await response.arrayBuffer()))
}

main().catch(error => {
  console.error(error)
  process.exitCode = 1
})

Python

import json
from pathlib import Path
import requests

url = "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Accept": "image/png",
}

response = requests.request(
    "GET",
    url,
    headers=headers,
    timeout=30,
)
response.raise_for_status()
Path("screenshot.png").write_bytes(response.content)

PHP

<?php

$curl = curl_init('https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop');

if ($curl === false) {
    throw new RuntimeException('Unable to initialize cURL');
}

curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer YOUR_API_KEY',
        'Accept: image/png',
    ],
]);

$response = curl_exec($curl);

if ($response === false) {
    $message = curl_error($curl);
    curl_close($curl);
    throw new RuntimeException('Network error: ' . $message);
}

$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE) ?: '';
curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException("HTTP $status: $response");
}

if (file_put_contents('screenshot.png', $response) === false) {
    throw new RuntimeException('Unable to save response file');
}

Go

package main

import (
	"context"
	"fmt"
	"io"
	"net/http"
	"os"
	"time"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Second)
	defer cancel()

	request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop", nil)
	if err != nil {
		panic(err)
	}

	request.Header.Set("Authorization", "Bearer YOUR_API_KEY")
	request.Header.Set("Accept", "image/png")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusMultipleChoices {
		errorBody, readErr := io.ReadAll(response.Body)
		if readErr != nil {
			panic(readErr)
		}
		panic(fmt.Sprintf("HTTP %d: %s", response.StatusCode, errorBody))
	}

	output, err := os.Create("screenshot.png")
	if err != nil {
		panic(err)
	}

	if _, err := io.Copy(output, response.Body); err != nil {
		output.Close()
		panic(err)
	}
	if err := output.Close(); err != nil {
		panic(err)
	}
}

Google Apps Script

function callLabrikaPublicAPI() {
  const response = UrlFetchApp.fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop", {
    method: "get",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "image/png",
    },
    followRedirects: false,
    muteHttpExceptions: true,
  });
  const status = response.getResponseCode();
  if (status < 200 || status >= 300) {
    throw new Error('HTTP ' + status + ': ' + response.getContentText());
  }
  DriveApp.createFile(response.getBlob().setName("screenshot.png"));
}