跳到主要内容
Bright Data 提供了一个强大的网络爬虫 API,允许您从 100 多个热门域中提取结构化数据,包括亚马逊产品详细信息、LinkedIn 个人资料等,这对于需要可靠结构化网络数据源的 AI 代理特别有用。

概览

集成详情

类别可序列化JS 支持版本
BrightDataWebScraperAPIlangchain-brightdataPyPI - Version

工具特性

原生异步返回工件返回数据定价
来自网站的结构化数据(亚马逊产品、LinkedIn 个人资料等)需要 Bright Data 账户

设置

该集成位于 langchain-brightdata 包中。
pip install langchain-brightdata
您需要一个 Bright Data API 密钥才能使用此工具。您可以将其设置为环境变量
import os

os.environ["BRIGHT_DATA_API_KEY"] = "your-api-key"
或者在初始化工具时直接传入
from langchain_brightdata import BrightDataWebScraperAPI

scraper_tool = BrightDataWebScraperAPI(bright_data_api_key="your-api-key")

实例化

这里我们展示如何实例化 BrightDataWebScraperAPI 工具。此工具允许您使用 Bright Data 的数据集 API 从各种网站提取结构化数据,包括亚马逊产品详细信息、LinkedIn 个人资料等。 该工具在实例化时接受各种参数:
  • bright_data_api_key(必需,str):用于身份验证的 Bright Data API 密钥。
  • dataset_mapping(可选,Dict[str, str]):一个字典,将数据集类型映射到其对应的 Bright Data 数据集 ID。默认映射包括
    • “amazon_product”: “gd_l7q7dkf244hwjntr0”
    • “amazon_product_reviews”: “gd_le8e811kzy4ggddlq”
    • “linkedin_person_profile”: “gd_l1viktl72bvl7bjuj0”
    • “linkedin_company_profile”: “gd_l1vikfnt1wgvvqz95w”

调用

基本用法

from langchain_brightdata import BrightDataWebScraperAPI

# Initialize the tool
scraper_tool = BrightDataWebScraperAPI(
    bright_data_api_key="your-api-key"  # Optional if set in environment variables
)

# Extract Amazon product data
results = scraper_tool.invoke(
    {"url": "https://www.amazon.com/dp/B08L5TNJHG", "dataset_type": "amazon_product"}
)

print(results)

带参数的高级用法

from langchain_brightdata import BrightDataWebScraperAPI

# Initialize with default parameters
scraper_tool = BrightDataWebScraperAPI(bright_data_api_key="your-api-key")

# Extract Amazon product data with location-specific pricing
results = scraper_tool.invoke(
    {
        "url": "https://www.amazon.com/dp/B08L5TNJHG",
        "dataset_type": "amazon_product",
        "zipcode": "10001",  # Get pricing for New York City
    }
)

print(results)

# Extract LinkedIn profile data
linkedin_results = scraper_tool.invoke(
    {
        "url": "https://www.linkedin.com/in/satyanadella/",
        "dataset_type": "linkedin_person_profile",
    }
)

print(linkedin_results)

自定义选项

BrightDataWebScraperAPI 工具接受几个用于自定义的参数
参数类型描述
URLstr要从中提取数据的 URL
dataset_typestr要使用的数据集类型(例如,“amazon_product”)
zipcodestr用于特定位置数据的可选邮政编码

可用数据集类型

该工具支持以下数据集类型用于结构化数据提取
数据集类型描述
amazon_product提取详细的亚马逊产品数据
amazon_product_reviews提取亚马逊产品评论
linkedin_person_profile提取 LinkedIn 个人资料数据
linkedin_company_profile提取 LinkedIn 公司资料数据

在代理中使用

from langchain_brightdata import BrightDataWebScraperAPI
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.agents import create_agent


# Initialize the LLM
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", google_api_key="your-api-key")

# Initialize the Bright Data Web Scraper API tool
scraper_tool = BrightDataWebScraperAPI(bright_data_api_key="your-api-key")

# Create the agent with the tool
agent = create_agent(llm, [scraper_tool])

# Provide a user query
user_input = "Scrape Amazon product data for https://www.amazon.com/dp/B0D2Q9397Y?th=1 in New York (zipcode 10001)."

# Stream the agent's step-by-step output
for step in agent.stream(
    {"messages": user_input},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()

API 参考


以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.