cURL
curl --request POST \
--url https://api.brightdata.com/datasets/filter \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"dataset_id": "<string>",
"filter": {
"name": "name",
"operator": "=",
"value": "John"
},
"records_limit": 123
}
'import requests
url = "https://api.brightdata.com/datasets/filter"
payload = {
"dataset_id": "<string>",
"filter": {
"name": "name",
"operator": "=",
"value": "John"
},
"records_limit": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
dataset_id: '<string>',
filter: {name: 'name', operator: '=', value: 'John'},
records_limit: 123
})
};
fetch('https://api.brightdata.com/datasets/filter', 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://api.brightdata.com/datasets/filter",
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([
'dataset_id' => '<string>',
'filter' => [
'name' => 'name',
'operator' => '=',
'value' => 'John'
],
'records_limit' => 123
]),
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/datasets/filter"
payload := strings.NewReader("{\n \"dataset_id\": \"<string>\",\n \"filter\": {\n \"name\": \"name\",\n \"operator\": \"=\",\n \"value\": \"John\"\n },\n \"records_limit\": 123\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/datasets/filter")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"dataset_id\": \"<string>\",\n \"filter\": {\n \"name\": \"name\",\n \"operator\": \"=\",\n \"value\": \"John\"\n },\n \"records_limit\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.brightdata.com/datasets/filter")
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 \"dataset_id\": \"<string>\",\n \"filter\": {\n \"name\": \"name\",\n \"operator\": \"=\",\n \"value\": \"John\"\n },\n \"records_limit\": 123\n}"
response = http.request(request)
puts response.read_body{
"snapshot_id": "<string>"
}{
"validation_errors": [
"\"filter.filters[0].invalid_prop\" is not allowed",
"\"records_limit\" must be a positive number"
]
}{
"error": "Your current balance is insufficient to process this data collection request. Please add funds to your account or adjust your request to continue. ($1 is missing)"
}{
"error": "Provided filter did not match any records"
}{
"error": "Maximum limit of 100 jobs per dataset has been exceeded"
}市场数据集 API
过滤数据集
Create a dataset snapshot based on a provided filter
POST
/
datasets
/
filter
cURL
curl --request POST \
--url https://api.brightdata.com/datasets/filter \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"dataset_id": "<string>",
"filter": {
"name": "name",
"operator": "=",
"value": "John"
},
"records_limit": 123
}
'import requests
url = "https://api.brightdata.com/datasets/filter"
payload = {
"dataset_id": "<string>",
"filter": {
"name": "name",
"operator": "=",
"value": "John"
},
"records_limit": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
dataset_id: '<string>',
filter: {name: 'name', operator: '=', value: 'John'},
records_limit: 123
})
};
fetch('https://api.brightdata.com/datasets/filter', 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://api.brightdata.com/datasets/filter",
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([
'dataset_id' => '<string>',
'filter' => [
'name' => 'name',
'operator' => '=',
'value' => 'John'
],
'records_limit' => 123
]),
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/datasets/filter"
payload := strings.NewReader("{\n \"dataset_id\": \"<string>\",\n \"filter\": {\n \"name\": \"name\",\n \"operator\": \"=\",\n \"value\": \"John\"\n },\n \"records_limit\": 123\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/datasets/filter")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"dataset_id\": \"<string>\",\n \"filter\": {\n \"name\": \"name\",\n \"operator\": \"=\",\n \"value\": \"John\"\n },\n \"records_limit\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.brightdata.com/datasets/filter")
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 \"dataset_id\": \"<string>\",\n \"filter\": {\n \"name\": \"name\",\n \"operator\": \"=\",\n \"value\": \"John\"\n },\n \"records_limit\": 123\n}"
response = http.request(request)
puts response.read_body{
"snapshot_id": "<string>"
}{
"validation_errors": [
"\"filter.filters[0].invalid_prop\" is not allowed",
"\"records_limit\" must be a positive number"
]
}{
"error": "Your current balance is insufficient to process this data collection request. Please add funds to your account or adjust your request to continue. ($1 is missing)"
}{
"error": "Provided filter did not match any records"
}{
"error": "Maximum limit of 100 jobs per dataset has been exceeded"
}一般描述
- 调用此端点将启动异步作业,以过滤数据集并在您的账户中创建包含过滤数据的快照。
- 该作业的最大完成时间为 5 分钟。如果在此时间范围内未完成,作业将被取消。
- 创建数据集快照的费用取决于快照大小和记录单价。
- 过滤组的最大嵌套深度为 3。
过滤语法
运算符
下表显示了可用于字段过滤的运算符。| 操作符 | 字段类型 | 描述 |
|---|---|---|
| = | 任意 | 等于 |
| != | 任意 | 不等于 |
| < | 数字, 日期 | 小于 |
| <= | 数字, 日期 | 小于或等于 |
| > | 数字, 日期 | 大于 |
| >= | 数字, 日期 | 大于或等于 |
in | 任意 | 测试字段值是否等于筛选值中提供的任意值 |
not_in | 任意 | 测试字段值是否不等于筛选值中提供的所有值 |
includes | 数组, 文本 | 测试字段值是否包含筛选值。如果筛选值是一个单一字符串,则匹配字段值包含该字符串的记录。如果筛选值是一个字符串数组,则匹配字段值包含数组中的至少一个字符串的记录。 |
not_includes | 数组, 文本 | 测试字段值是否不包含筛选值。如果筛选值是一个单一字符串,则匹配字段值不包含该字符串的记录。如果筛选值是一个字符串数组,则匹配字段值不包含数组中的任何字符串的记录。 |
array_includes | 数组 | 测试筛选值是否在字段值中(精确匹配) |
not_array_includes | 数组 | 测试筛选值是否不在字段值中(精确匹配) |
is_null | 任意 | 测试字段值是否等于 NULL。操作符不接受任何值。 |
is_not_null | 任意 | 测试字段值是否不等于 NULL。操作符不接受任何值。 |
组合多个筛选器
可以使用两个逻辑运算符:‘and’(与),‘or’(或)将多个字段筛选器组合成筛选器组。API 支持最多 3 层嵌套的筛选器。
筛选器组示例:
{
// operator can be one of ["and", "or"]
"operator": "and",
// an array of field filters
"filters": [
{
"name": "reviews_count",
"opeartor": ">",
"value": "200"
},
{
"name": "rating",
"operator": ">",
"value": "4.5"
}
]
}
授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
请求体
application/json
响应
Job of creating the snapshot successfully started
ID of the snapshot