API代码示例 | Python JavaScript Go Java PHP 截图 — 网站截图服务平台

📝 API 代码示例

任意语言都能用。复制以下代码,替换 sk_your_key 即可。

Python

python
import requests

# 网页截图
r = requests.get(
    "http://8.222.180.187:8000/api/v1/screenshot",
    params={"url": "https://example.com", "width": 1920, "height": 1080},
    headers={"x-api-key": "sk_your_key"}
)
data = r.json()
print(data["download_url"])

# 网页转PDF
r = requests.get(
    "http://8.222.180.187:8000/api/v1/pdf",
    params={"url": "https://example.com"},
    headers={"x-api-key": "sk_your_key"}
)
with open("output.pdf", "wb") as f:
    f.write(requests.get(data["download_url"]).content)

JavaScript / Node.js

javascript
// 网页截图
const res = await fetch(
  `http://8.222.180.187:8000/api/v1/screenshot?url=${encodeURIComponent(url)}&width=1920&height=1080`,
  { headers: { "x-api-key": "sk_your_key" } }
);
const data = await res.json();
console.log(data.download_url);

// 文字提取
const textRes = await fetch(
  `http://8.222.180.187:8000/api/v1/extract-text?url=${encodeURIComponent(url)}`,
  { headers: { "x-api-key": "sk_your_key" } }
);
const { text } = await textRes.json();
console.log(text);

Go

go
package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "http://8.222.180.187:8000/api/v1/screenshot?url=https://example.com&width=1920&height=1080"
    req, _ := http.NewRequest("GET", url, nil)
    req.Header.Set("x-api-key", "sk_your_key")
    resp, _ := http.DefaultClient.Do(req)
    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Java

java
import java.net.http.*;
import java.net.URI;

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("http://8.222.180.187:8000/api/v1/screenshot?url=https://example.com&width=1920&height=1080"))
    .header("x-api-key", "sk_your_key")
    .GET()
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

PHP

php
// 网页截图
$url = "http://8.222.180.187:8000/api/v1/screenshot?url=https://example.com&width=1920&height=1080";
$opts = ["http" => ["header" => "x-api-key: sk_your_key"]];
$data = file_get_contents($url, false, stream_context_create($opts));
$result = json_decode($data, true);
echo $result["download_url"];

cURL

bash
# 截图
curl -H "x-api-key: sk_your_key" \
  "http://8.222.180.187:8000/api/v1/screenshot?url=https://example.com&width=1920&height=1080"

# 转PDF
curl -H "x-api-key: sk_your_key" \
  "http://8.222.180.187:8000/api/v1/pdf?url=https://example.com"

# 提取文字
curl -H "x-api-key: sk_your_key" \
  "http://8.222.180.187:8000/api/v1/extract-text?url=https://example.com"
免费注册获取API密钥 →