网页抓取 API
异步任务
jobs 端点将抓取任务加入队列,并允许轮询状态和结果 — 适合高并发或加载较慢的页面。
POST
/
v1
/
jobs
异步任务
curl --request POST \
--url https://scrape.cleariflow.com/v1/jobs \
--header 'Content-Type: application/json' \
--data '
{
"request": {},
"priority": 123
}
'import requests
url = "https://scrape.cleariflow.com/v1/jobs"
payload = {
"request": {},
"priority": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({request: {}, priority: 123})
};
fetch('https://scrape.cleariflow.com/v1/jobs', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://scrape.cleariflow.com/v1/jobs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'request' => [
],
'priority' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://scrape.cleariflow.com/v1/jobs"
payload := strings.NewReader("{\n \"request\": {},\n \"priority\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://scrape.cleariflow.com/v1/jobs")
.header("Content-Type", "application/json")
.body("{\n \"request\": {},\n \"priority\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://scrape.cleariflow.com/v1/jobs")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"request\": {},\n \"priority\": 123\n}"
response = http.request(request)
puts response.read_body{
"job_id": "550e8400-e29b-41d4-a716-446655440000"
}
入门
基础 URL
https://scrape.cleariflow.com/v1/jobs
创建任务
使用与同步端点相同的ScrapeRequest 负载将异步抓取任务入队。
请求示例
curl -X POST 'https://scrape.cleariflow.com/v1/jobs' \
-H 'Content-Type: application/json' \
-d '{
"request": {
"api_key": "YOUR_UNIQUE_API_KEY",
"url": "https://example.com"
},
"priority": 10
}'
{
"job_id": "550e8400-e29b-41d4-a716-446655440000"
}
创建任务参数
Object
必填
与同步抓取端点字段相同的
ScrapeRequest 对象(url、render、actions、cookies 等)。Integer
任务优先级。数值越高越先处理。默认:0。
获取任务状态
通过 ID 轮询任务以检查状态,并在完成后获取结果。基础 URL
https://scrape.cleariflow.com/v1/jobs/{job_id}
请求示例
curl 'https://scrape.cleariflow.com/v1/jobs/550e8400-e29b-41d4-a716-446655440000'
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "running"
}
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "done",
"result": {
"ok": true,
"html": "<!DOCTYPE html><html>...</html>",
"meta": {
"elapsed_ms": 8123
}
}
}
任务状态值
| 状态 | 说明 |
|---|---|
queued | 任务在队列中等待。 |
running | 浏览器会话活跃中。 |
done | 抓取完成;result 包含输出。 |
failed | 抓取失败;error 包含错误描述。 |
响应参数
String
异步任务的唯一标识符。
String
当前任务状态:
queued、running、done 或 failed。Object
抓取结果对象(与同步端点响应结构相同)。当
status 为 done 时返回。String
错误消息。当
status 为 failed 时返回。Object
有关任务执行的额外元数据。
⌘I
异步任务
curl --request POST \
--url https://scrape.cleariflow.com/v1/jobs \
--header 'Content-Type: application/json' \
--data '
{
"request": {},
"priority": 123
}
'import requests
url = "https://scrape.cleariflow.com/v1/jobs"
payload = {
"request": {},
"priority": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({request: {}, priority: 123})
};
fetch('https://scrape.cleariflow.com/v1/jobs', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://scrape.cleariflow.com/v1/jobs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'request' => [
],
'priority' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://scrape.cleariflow.com/v1/jobs"
payload := strings.NewReader("{\n \"request\": {},\n \"priority\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://scrape.cleariflow.com/v1/jobs")
.header("Content-Type", "application/json")
.body("{\n \"request\": {},\n \"priority\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://scrape.cleariflow.com/v1/jobs")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"request\": {},\n \"priority\": 123\n}"
response = http.request(request)
puts response.read_body{
"job_id": "550e8400-e29b-41d4-a716-446655440000"
}