Skip to main content
本指南向您展示如何设置webhook交付,以便在集合任务完成时您的服务器自动接收爬取的LinkedIn数据。

先决条件

Webhook如何工作

当您触发带有webhook URL的异步集合时,Bright Data会在任务完成后向您的端点发送一个POST请求,携带爬取的数据。无需轮询。
您的应用 --> POST /trigger (带webhook URL) --> Bright Data爬取 --> POST到您的webhook

第1步:设置测试webhook

为了测试,使用webhook.site获取临时公共URL:
  1. 在浏览器中打开webhook.site
  2. 复制显示的唯一URL(例如,https://webhook.site/abc-123-def
  3. 保持页面打开以监控传入的请求

第2步:使用webhook URL触发集合

在异步/trigger请求中添加webhook查询参数:
curl -X POST \
  "https://api.brightdata.com/datasets/v3/trigger?dataset_id=gd_l1viktl72bvl7bjuj0&format=json&webhook=https://webhook.site/abc-123-def&uncompressed_webhook=true" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[
    {"url": "https://www.linkedin.com/in/satyanadella"},
    {"url": "https://www.linkedin.com/in/jeffweiner08"}
  ]'
关键参数:
参数描述
webhook接收POST负载的HTTP端点URL
uncompressed_webhook设置为true以接收未压缩的JSON(默认为gzip)
format输出格式:jsonndjsoncsv

第3步:验证交付

集合完成后(通常需要30-60秒来处理几个档案),检查您的webhook.site页面。您应该看到一个包含爬取数据的POST请求。 负载与您从直接API下载接收的JSON数组相同:
[
  {
    "name": "Satya Nadella",
    "city": "Redmond",
    "country_code": "US",
    "current_company": { "name": "Microsoft" },
    "followers": 10842560
  },
  {
    "name": "Jeff Weiner",
    "city": "San Francisco Bay Area",
    "country_code": "US",
    "current_company": { "name": "Next Chapter" },
    "followers": 1200000
  }
]

生产环境webhook设置

对于生产环境,将webhook URL指向您自己的服务器端点。

Express.js处理程序

server.js
const express = require("express");
const app = express();

app.use(express.json({ limit: "100mb" }));

app.post("/webhook/linkedin", (req, res) => {
  const profiles = req.body;
  console.log(`Received ${profiles.length} profiles`);

  for (const profile of profiles) {
    console.log(`- ${profile.name} (${profile.current_company?.name})`);
  }

  res.status(200).json({ received: true });
});

app.listen(3000, () => console.log("Webhook server running on port 3000"));

Flask处理程序

server.py
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/webhook/linkedin", methods=["POST"])
def handle_webhook():
    profiles = request.get_json()
    print(f"Received {len(profiles)} profiles")

    for profile in profiles:
        print(f"- {profile['name']} ({profile.get('current_company', {}).get('name')})")

    return jsonify({"received": True}), 200

if __name__ == "__main__":
    app.run(port=3000)
在30秒内返回200状态码以确认收到。如果您的端点失败或超时,Bright Data会重试交付。

带授权的Webhook

如果您的端点需要身份验证,添加webhook_header_Authorization参数:
curl -X POST \
  "https://api.brightdata.com/datasets/v3/trigger?dataset_id=gd_l1viktl72bvl7bjuj0&format=json&webhook=https://your-server.com/webhook&webhook_header_Authorization=Bearer+YOUR_SECRET_TOKEN" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://www.linkedin.com/in/satyanadella"}]'

允许列表webhook IP

如果您的服务器使用IP允许列表,请添加以下Bright Data webhook源IP:
54.175.27.69
34.225.9.175
100.28.38.247
100.29.18.195
52.72.185.255
35.174.112.248
54.165.183.124
3.91.140.7
52.202.75.37
98.82.225.117
100.27.150.189
18.214.10.85
35.169.71.210
44.194.183.74

故障排除

  • 验证URL是否可公开访问(不是localhost
  • 检查您的端点是否在30秒内返回200状态码
  • 如果您有防火墙规则,验证上述webhook IP是否在允许列表中
如果您省略uncompressed_webhook=true,数据将以gzip压缩格式到达。将uncompressed_webhook=true添加到您的触发URL,或在您的服务器上解压负载。
大型集合可能会产生高达1 GB的负载。在Express.js中设置express.json({ limit: "100mb" })或在您的框架中设置等效配置。如果您需要处理非常大的数据集,改用S3交付

后续步骤

交付到Amazon S3

直接在您的S3存储桶中存储结果。

所有交付选项

Snowflake、Azure、GCS等。