Python SDK
# Install: pip install brightdata-sdk
import asyncio
from brightdata import BrightDataClient
async def main():
async with BrightDataClient(token="YOUR_API_KEY", auto_create_zones=False) as client:
# Run and get results in one call (sync)
data = await client.scraper_studio.run(
collector="c_abc123",
input={"url": "https://www.ebay.com/itm/326972541236"},
)
print(data)
asyncio.run(main())// Install: npm install @brightdata/sdk
import { bdclient } from '@brightdata/sdk';
const client = new bdclient({ apiKey: 'YOUR_API_KEY' });
// Run and get results in one call (sync)
const results = await client.scraperStudio.run('c_your_collector_id', {
input: { url: 'https://www.ebay.com/itm/326972541236' },
});
console.log(results);
await client.close();curl --request POST \
--url https://api.brightdata.com/dca/crawl \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://www.ebay.com/itm/326972541236"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.brightdata.com/dca/crawl",
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([
'url' => 'https://www.ebay.com/itm/326972541236'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.brightdata.com/dca/crawl"
payload := strings.NewReader("{\n \"url\": \"https://www.ebay.com/itm/326972541236\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://api.brightdata.com/dca/crawl")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://www.ebay.com/itm/326972541236\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.brightdata.com/dca/crawl")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://www.ebay.com/itm/326972541236\"\n}"
response = http.request(request)
puts response.read_body[
{
"product_title": "Apple iPad 11th Gen, 128 GB, Wi-Fi + 5G, 11 in - Silver - BRAND NEW SEALED",
"price": {
"value": 324.99,
"currency": "USD",
"symbol": "$"
},
"condition": "New: A brand-new, unused, unopened, undamaged item in its original packaging (where packaging is ...",
"seller_feedback_percentage": "100% positive feedback",
"seller_items_sold": "173 items sold",
"seller_since": "Joined Nov 2012",
"item_specifics": {
"brand": "Apple",
"model": "Apple iPad (11th generation)",
"processor_model": "Apple A16 Bionic",
"operating_system": "iPadOS"
},
"storage_options": [],
"seller_ratings": {
"accurate_description": "--",
"shipping_cost": "--",
"shipping_speed": "--",
"communication": "4.9"
},
"product_images": [
"https://i.ebayimg.com/images/g/4a8AAeSw7x5pboS0/s-l1600.webp",
"https://i.ebayimg.com/images/g/4a8AAeSw7x5pboS0/s-l1600.webp"
],
"feedback_count": 36,
"financing_options": {
"monthly_payment": {
"value": 13.99,
"currency": "USD",
"symbol": "$"
},
"payment_plan_duration": "(12 monthly payment plan)",
"apr": "13.99%"
},
"input": {
"url": "https://www.ebay.com/itm/326972541236"
},
"seller_namestest": "jwc8109"
}
]{
"error": "crawl_results_timeout",
"message": "Timed out waiting for crawl results (timeout=NaNs). The page crawl is continuing in the background, you can poll a GET request to https://api.brightdata.com/dca/get_result?response_id=ID until the result is ready",
"response_id": "RESPONSE_ID"
}发起采集
同步触发爬虫进行实时数据采集
触发同步实时 Scraper Studio 采集。POST /dca/crawl 会保持请求打开,直到爬虫完成或达到超时,然后以 JSON 形式直接返回数据。
POST
/
dca
/
crawl
Python SDK
# Install: pip install brightdata-sdk
import asyncio
from brightdata import BrightDataClient
async def main():
async with BrightDataClient(token="YOUR_API_KEY", auto_create_zones=False) as client:
# Run and get results in one call (sync)
data = await client.scraper_studio.run(
collector="c_abc123",
input={"url": "https://www.ebay.com/itm/326972541236"},
)
print(data)
asyncio.run(main())// Install: npm install @brightdata/sdk
import { bdclient } from '@brightdata/sdk';
const client = new bdclient({ apiKey: 'YOUR_API_KEY' });
// Run and get results in one call (sync)
const results = await client.scraperStudio.run('c_your_collector_id', {
input: { url: 'https://www.ebay.com/itm/326972541236' },
});
console.log(results);
await client.close();curl --request POST \
--url https://api.brightdata.com/dca/crawl \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://www.ebay.com/itm/326972541236"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.brightdata.com/dca/crawl",
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([
'url' => 'https://www.ebay.com/itm/326972541236'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.brightdata.com/dca/crawl"
payload := strings.NewReader("{\n \"url\": \"https://www.ebay.com/itm/326972541236\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://api.brightdata.com/dca/crawl")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://www.ebay.com/itm/326972541236\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.brightdata.com/dca/crawl")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://www.ebay.com/itm/326972541236\"\n}"
response = http.request(request)
puts response.read_body[
{
"product_title": "Apple iPad 11th Gen, 128 GB, Wi-Fi + 5G, 11 in - Silver - BRAND NEW SEALED",
"price": {
"value": 324.99,
"currency": "USD",
"symbol": "$"
},
"condition": "New: A brand-new, unused, unopened, undamaged item in its original packaging (where packaging is ...",
"seller_feedback_percentage": "100% positive feedback",
"seller_items_sold": "173 items sold",
"seller_since": "Joined Nov 2012",
"item_specifics": {
"brand": "Apple",
"model": "Apple iPad (11th generation)",
"processor_model": "Apple A16 Bionic",
"operating_system": "iPadOS"
},
"storage_options": [],
"seller_ratings": {
"accurate_description": "--",
"shipping_cost": "--",
"shipping_speed": "--",
"communication": "4.9"
},
"product_images": [
"https://i.ebayimg.com/images/g/4a8AAeSw7x5pboS0/s-l1600.webp",
"https://i.ebayimg.com/images/g/4a8AAeSw7x5pboS0/s-l1600.webp"
],
"feedback_count": 36,
"financing_options": {
"monthly_payment": {
"value": 13.99,
"currency": "USD",
"symbol": "$"
},
"payment_plan_duration": "(12 monthly payment plan)",
"apr": "13.99%"
},
"input": {
"url": "https://www.ebay.com/itm/326972541236"
},
"seller_namestest": "jwc8109"
}
]{
"error": "crawl_results_timeout",
"message": "Timed out waiting for crawl results (timeout=NaNs). The page crawl is continuing in the background, you can poll a GET request to https://api.brightdata.com/dca/get_result?response_id=ID until the result is ready",
"response_id": "RESPONSE_ID"
}同步实时端点会保持 HTTP 请求处于打开状态,直到爬虫完成或达到
timeout,然后以 JSON 形式直接返回采集到的数据。这与异步实时端点不同,后者会立即返回一个 response_id。
你只能触发单输入 API。确保有效载荷是一个对象,而不是对象数组。
超时行为
timeout 查询参数的取值必须在 25s 到 50s 之间。
- 如果爬虫在超时时间内完成,响应返回
200 OK以及采集到的数据。 - 如果到达超时时爬虫仍在运行,响应返回
202 Accepted以及一个response_id。使用该response_id调用实时数据端点以异步方式获取结果。
何时使用同步实时
在以下情况下使用同步实时(POST /dca/crawl):
- 你需要在同一个 HTTP 请求中获得结果。
- 你只发送单个输入。
- 你的客户端可以保持请求打开,直到采集完成。
- 采集通常在配置的超时时间内完成。
POST /dca/trigger_immediate):
- 你希望先触发采集,稍后再获取结果。
- 你不希望保持 HTTP 请求处于打开状态。
- 你需要在一次运行中处理多个输入。
授权
在 Authorization 头中使用您的 Bright Data API Key 作为 Bearer token。
认证方法:
- 从 Bright Data 账户设置获取您的 API Key: https://brightdata.com/cp/setting/users
- 在请求的 Authorization 头中包含 API Key
- 格式:
Authorization: Bearer YOUR_API_KEY
示例:
Authorization: Bearer b5648e1096c6442f60a6c4bbbe73f8d2234d3d8324554bd6a7ec8f3f251f07df
了解如何获取 Bright Data API Key: https://docs.brightdata.com/cn/api-reference/authentication#如何生成新的-api-key?
查询参数
要运行的爬虫的唯一标识
示例:
"c_abc123"
等待结果时请求保持打开的时长,必须在 25s 到 50s 之间。如果爬虫在超时时间内完成,响应返回 200 OK 和采集到的数据。如果达到超时时间时爬虫仍在运行,响应返回 202 Accepted 和 response_id。
示例:
"50s"
设置为 dev 以触发 scraper 的开发版本
请求体
application/json
单个输入对象。字段必须与爬虫定义的输入 schema 一致。基于 URL 的爬虫可能需要 url,而搜索类爬虫可能需要 keyword 和 location 等字段。
单个输入对象,其字段与爬虫的输入 schema 一致。
适用于接收目标 URL 的爬虫的示例字段。请替换为您的爬虫所需的字段。
响应
OK
此页面对您有帮助吗?