使用 Fetch API 按 URL 抓取任意网页
curl --request POST \
--url https://api.brightdata.com/datasets/v3/scrape \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"input": [
{
"url": "<string>",
"country": "<string>"
}
]
}
'import requests
url = "https://api.brightdata.com/datasets/v3/scrape"
payload = { "input": [
{
"url": "<string>",
"country": "<string>"
}
] }
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({input: [{url: '<string>', country: '<string>'}]})
};
fetch('https://api.brightdata.com/datasets/v3/scrape', 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/v3/scrape",
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([
'input' => [
[
'url' => '<string>',
'country' => '<string>'
]
]
]),
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/v3/scrape"
payload := strings.NewReader("{\n \"input\": [\n {\n \"url\": \"<string>\",\n \"country\": \"<string>\"\n }\n ]\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/v3/scrape")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"input\": [\n {\n \"url\": \"<string>\",\n \"country\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.brightdata.com/datasets/v3/scrape")
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 \"input\": [\n {\n \"url\": \"<string>\",\n \"country\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body[
{
"url": "https://example.com",
"final_url": "https://example.com/",
"page_title": "Example Domain",
"country": "us",
"markdown": "# Example Domain\n\nThis domain is for use in illustrative examples in documents.",
"html2text": "Example Domain\n\nThis domain is for use in illustrative examples in documents.",
"page_html": "<!doctype html><html><head><title>Example Domain</title></head><body><div><h1>Example Domain</h1><p>This domain is for use in illustrative examples in documents.</p></div></body></html>",
"ld_json": null
}
]
网页内容 API
使用 Fetch API 按 URL 抓取任意网页
使用 Bright Data Fetch API 爬虫按 URL 采集任意公开网页,以 Markdown、纯文本、原始 HTML 或 JSON-LD 格式返回,并可通过 country 参数指定国家。发送 POST /datasets/v3/scrape 获取结果。
POST
/
datasets
/
v3
/
scrape
使用 Fetch API 按 URL 抓取任意网页
curl --request POST \
--url https://api.brightdata.com/datasets/v3/scrape \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"input": [
{
"url": "<string>",
"country": "<string>"
}
]
}
'import requests
url = "https://api.brightdata.com/datasets/v3/scrape"
payload = { "input": [
{
"url": "<string>",
"country": "<string>"
}
] }
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({input: [{url: '<string>', country: '<string>'}]})
};
fetch('https://api.brightdata.com/datasets/v3/scrape', 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/v3/scrape",
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([
'input' => [
[
'url' => '<string>',
'country' => '<string>'
]
]
]),
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/v3/scrape"
payload := strings.NewReader("{\n \"input\": [\n {\n \"url\": \"<string>\",\n \"country\": \"<string>\"\n }\n ]\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/v3/scrape")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"input\": [\n {\n \"url\": \"<string>\",\n \"country\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.brightdata.com/datasets/v3/scrape")
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 \"input\": [\n {\n \"url\": \"<string>\",\n \"country\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body[
{
"url": "https://example.com",
"final_url": "https://example.com/",
"page_title": "Example Domain",
"country": "us",
"markdown": "# Example Domain\n\nThis domain is for use in illustrative examples in documents.",
"html2text": "Example Domain\n\nThis domain is for use in illustrative examples in documents.",
"page_html": "<!doctype html><html><head><title>Example Domain</title></head><body><div><h1>Example Domain</h1><p>This domain is for use in illustrative examples in documents.</p></div></body></html>",
"ld_json": null
}
]
Fetch API(原 Crawl API)是 Web Unlocker API 在 Scraper API 中的对应产品。发送任意公开 URL,即可在一条记录中获取该网页的 Markdown、纯文本、原始 HTML 和 JSON-LD。
如只需要部分字段,请设置
查询参数
string
默认值:"gd_m6gjtfmeh43we6cqc"
必填
用于此请求的数据集 ID。
必须设置为
gd_m6gjtfmeh43we6cqc 才能采集 Fetch API - 按 URL 采集 数据。boolean
默认值:false
请求完成时是否发送通知。
boolean
默认值:true
是否在响应中包含错误。
string
仅返回列出的输出字段,字段之间用竖线(
|)分隔。例如,url|markdown 仅返回 URL 和网页的 Markdown 版本。请求体
object[]
必填
输出字段
每条记录包含以下字段:| 字段 | 类型 | 说明 |
|---|---|---|
url | url | 输入的 URL |
final_url | url | 重定向后的 URL |
page_title | text | 网页标题 |
country | country | 获取网页时使用的国家 |
markdown | Markdown | 以 Markdown 格式呈现的网页内容,保留标题、列表和链接 |
html2text | text | 去除所有 HTML 标签和格式后的网页文本 |
page_html | HTML | 完整的 HTML 源代码,包括标签、脚本和样式 |
ld_json | JSON | 网页中的 JSON-LD 结构化元数据,例如 schema.org 数据 |
custom_output_fields,例如 custom_output_fields=url|markdown。
[
{
"url": "https://example.com",
"final_url": "https://example.com/",
"page_title": "Example Domain",
"country": "us",
"markdown": "# Example Domain\n\nThis domain is for use in illustrative examples in documents.",
"html2text": "Example Domain\n\nThis domain is for use in illustrative examples in documents.",
"page_html": "<!doctype html><html><head><title>Example Domain</title></head><body><div><h1>Example Domain</h1><p>This domain is for use in illustrative examples in documents.</p></div></body></html>",
"ld_json": null
}
]
此页面对您有帮助吗?