跳转到主要内容

安装包

打开终端并运行:
npm install @brightdata/sdk
在你的代码文件中,导入包并发起你的第一次请求:
import { bdclient } from '@brightdata/sdk';

const client = new bdclient({
    apiKey: '[your_api_key_here]' // 也可以通过 BRIGHTDATA_API_KEY 环境变量定义
});
const result = await client.search('pizza restaurants');

console.log(result);

发起抓取和网络搜索

尝试这些示例,从你的 IDE 搜索或抓取互联网数据
import { bdclient } from '@brightdata/sdk';

const client = new bdclient({
    apiKey: '[your_api_key_here]' // 也可以通过 BRIGHTDATA_API_KEY 环境变量定义
});
const result = await client.search('pizza restaurants');

console.log(result);

访问我们的 Linkedin 数据集

尝试这些示例,从你的 IDE 使用 Bright Data 的 Linkedin 数据集
import { bdclient } from '@brightdata/sdk';

const client = new bdclient({
    apiKey: 'YOUR_API_KEY_HERE',
    logLevel: 'INFO',
    structuredLogging: true,
    verbose: false
});

const res = await client.datasets.linkedin.discoverCompanyPosts([
    { url: 'https://www.linkedin.com/company/bright-data' },
]);

// 如果快照准备好,它将轮询,并下载
const filePath = await client.datasets.snapshot.download(res.snapshot_id, {
    filename: './brd_posts.jsonl',
    format: 'jsonl',
});

console.log(`内容已保存到: ${filePath}`);
const client = new bdclient({
    apiKey: 'string', // 你的 API key
    autoCreateZones: true, // 如果不存在则自动创建 zone
    webUnlockerZone: 'string', // 自定义 Web Unlocker zone 名称
    serpZone: 'string', // 自定义 SERP zone 名称
    logLevel: 'INFO', // 日志等级
    structuredLogging: true, // 使用结构化 JSON 日志
    verbose: false, // 启用详细日志
});
使用 SERP API 搜索网络
名称类型描述默认值
query`stringstring[]`搜索查询字符串或查询数组
options.searchEngine`“google""bing""yandex”`搜索引擎"google"
options.zonestring区域标识符(如果为空则自动配置)
options.format`“json""raw”`响应格式"raw"
options.methodstringHTTP 方法"GET"
options.countrystring两位国家代码""
options.dataFormat`“markdown""screenshot""html”`返回内容格式"html"
options.concurrencynumber最大并行任务数10
options.timeoutnumber (ms)请求超时30000
使用 Web Unlocker API 抓取单个 URL 或 URL 列表
名称类型描述默认值
url`stringstring[]`单个 URL 字符串或 URL 数组
options.zonestring区域标识符(如果为空则自动配置)
options.format`“json""raw”`响应格式"raw"
options.methodstringHTTP 方法"GET"
options.countrystring两位国家代码""
options.dataFormat`“markdown""screenshot""html”`返回内容格式"html"
options.concurrencynumber最大并行任务数10
options.timeoutnumber (ms)请求超时30000
参数:
名称类型描述默认值
contentany要保存的内容
options.filenamestring输出文件名(如果为空则自动生成)
options.format`“json""csv""txt”`文件格式

错误处理

在客户端中启用 VERBOSE 以进行高级日志记录(参见客户端参数) 使用 listZones() 函数检查可用 zone
创建一个 Bright Data 账户并复制你的 API key,前往 账户设置,确保你的 API key 具有 管理员权限

资源