CaptureKit

Die Antwort prüfen

Stellen Sie sicher, dass die Antwort ein Bild ist, bevor Sie sie speichern.

Der Header Content-Type nennt das Format der Datei: hier image/png (application/pdf mit format=pdf). Ein Fehler kommt als JSON mit einem HTTP-Fehlerstatus.

Dieser Code setzt das Skript aus Einen Screenshot anfordern fort.

content_type = response.headers.get("content-type", "")
if not content_type.startswith("image/"):
    raise SystemExit(f"Expected an image, got {content_type}: {response.text}")
print(f"Content type: {content_type}")