# Web Fetch API

通过 selector 和 readability 选项，将网页内容提取为 HTML、text 或 Markdown。

本页介绍原 `/v2` Felo APIs，沿用 **Felo 账户权益与 Pro 积分规则**。具体是否扣费见[各能力的积分规则](https://openapi.felo.ai/zh-CN/docs/faq/billing-and-credits.md#v2-各能力的积分规则)。需要使用平台余额时，请选择 [Felo（Data API）](https://openapi.felo.ai/zh-CN/docs/api-reference/openapi/overview.md)中对应的接口；两套接口的参数和返回结构可能不同。


Web Fetch API 从目标 URL 提取内容，并返回更适合 agents、RAG systems 和 content workflows 处理的结果。它可返回 HTML、plain text 或 Markdown，并支持 selectors、readability options、cache control、custom user agents 和 request cookies。

## Endpoint

```http
POST https://openapi.felo.ai/v2/web/extract
```

## 认证

```http
Authorization: Bearer YOUR_API_KEY
```

## Body Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `url` | string | 是 | - | 要提取的网页 URL |
| `crawl_mode` | string | 否 | `fast` | `fast` 更快；`fine` 更精细，适合复杂页面 |
| `output_format` | string | 否 | `html` | 支持 `html`、`text`、`markdown` |
| `with_readability` | boolean or string | 否 | - | 启用 readability 处理，聚焦主要内容 |
| `target_selector` | string | 否 | - | 目标 CSS selector，例如 `article.main-content` |
| `wait_for_selector` | string | 否 | - | 等待 selector 出现后再提取，适合动态页面 |
| `set_cookies` | array | 否 | - | 随请求发送 cookies |
| `user_agent` | string | 否 | - | 自定义 User-Agent |
| `timeout` | integer | 否 | - | 请求 timeout，单位 ms |

## 响应

`data` 采用透明透传设计，具体字段取决于 `output_format` 和 options。

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "example-request-id",
  "data": { "content": "# Example Article\n\nExtracted article content..." }
}
```

## Error Responses

| HTTP Status | Error Code | 说明 | 建议操作 |
|-------------|------------|-------------|------------------|
| 400 | `WEB_EXTRACT_FAILED` | URL 无效、请求参数错误或 extractor 返回客户端错误 | 检查 `url`、selectors 和参数 |
| 401 | `UNAUTHORIZED` | API key 缺失、无效或已撤销 | 检查 API key 和 authorization header |
| 500 | `WEB_EXTRACT_FAILED` | 内部服务错误 | 重试；持续失败请联系 support |

## Example

```bash
curl -X POST https://openapi.felo.ai/v2/web/extract   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"url":"https://example.com/article","output_format":"markdown","with_readability":true}'
```

## 使用场景

- 在 Agent 回答问题前提供网页上下文
- 为 RAG ingestion 或 knowledge base creation 提取文章正文
- 将网页转换为 Markdown，用于归档或文档工作流
- 使用 CSS selectors 从页面中提取聚焦内容
