网页抓取

访问指定网页并抽取正文内容,适合文档总结、网页问答与多工具编排场景

概述

网页抓取依赖百炼侧的 web_extractor 工具。Ling.AI 不会自行抓网页,而是将网页抓取相关参数和工具定义原样透传给上游。对 Chat Completions / DashScope 场景,常见做法是把 search_strategy 设为 agent_max;对 /v1/responses,则通过工具列表直接启用。

前置条件

网页抓取通常与联网搜索一起使用。Responses API 下请同时传入 web_searchweb_extractor;若需要计算、表格处理或进一步分析,建议再开启 code_interpreter

Responses API

/v1/responses 是网页抓取的首选方式。直接通过 tools 声明 web_searchweb_extractorcode_interpreter 即可。

Python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.vip.lingapi.ai/v1",
    api_key="sk-xxxxxxxx"
)

response = client.responses.create(
    model="qwen3-max-2026-01-23",
    input="请访问阿里云百炼代码解释器部分的官方文档,并总结主要内容",
    tools=[
        {"type": "web_search"},
        {"type": "web_extractor"},
        {"type": "code_interpreter"}
    ],
    enable_thinking=True
)

print(response.output_text)

当上游返回工具使用明细时,网页抓取和联网搜索调用次数通常会反映在 usage.x_tools 或 Responses 输出项中,网关会保留这些字段供审计与工具计费使用。

Chat Completions

/v1/chat/completions 中,网页抓取通过联网搜索策略 agent_max 启用。常见要求是同时打开 enable_searchenable_thinking

Python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.vip.lingapi.ai/v1",
    api_key="sk-xxxxxxxx"
)

stream = client.chat.completions.create(
    model="qwen3-max-2026-01-23",
    messages=[
        {"role": "user", "content": "请访问官方文档并总结主要内容"}
    ],
    extra_body={
        "enable_thinking": True,
        "enable_search": True,
        "search_options": {
            "search_strategy": "agent_max"
        }
    },
    stream=True
)

流式限制

对于百炼网页抓取场景,Chat Completions 与 DashScope 一般只支持流式输出。若您看到上游文档强调“不支持非流式输出”,请直接按流式方式接入。

DashScope

DashScope 协议下同样使用 enable_searchsearch_strategy=agent_max 启用网页抓取,并通常要求 enable_thinkingtrue

Python
from dashscope import Generation

response = Generation.call(
    model="qwen3-max-2026-01-23",
    messages=[
        {"role": "user", "content": "请访问官方文档并总结主要内容"}
    ],
    enable_search=True,
    search_options={"search_strategy": "agent_max"},
    enable_thinking=True,
    result_format="message",
    stream=True,
    incremental_output=True
)

流式中间过程

使用 Responses 流式输出时,网页抓取的阶段性结果通常会出现在 response.output_item.done 事件中,类型可能为 web_extractor_call。如果需要展示抓取过程,可以优先监听这类事件。

计费说明

  • 网页内容会被拼接到模型上下文中,因此会增加输入 Token 成本。
  • 联网搜索与网页抓取调用次数会进入工具计费链路;如果上游返回 web_extractor / web_search 的使用次数,网关会保留并结算。
  • 当前系统内置的官方工具默认值中,web_extractor 仍按“限时免费 / 当前免费”处理;如上游价格调整,可在后台工具计费规则中覆盖。