# 关键词密度

**API:** Data API

**Endpoint:** `POST /v1/beta/dataforseo/on_page/keyword_density`

**Tags:** DataForSEO

一次爬取中的词频与短语频次，`keyword_length` 决定 n-gram 的大小。返回 `total_items_count`、`items_count` 和 `items`。读取已完成的爬取，因此需要 `post_dataforseo_on_page_submit` 返回的 `id`，并返回 `crawl_progress` 以及 `crawl_status`（`max_crawl_pages`、`pages_in_queue` 和 `pages_crawled`）——在采信偏少的结果前先检查这些字段，因为仍在进行的爬取能报告的内容本来就少。这里描述的是站点对自己的陈述；若要了解网络如何评价它，请使用 `post_dataforseo_backlinks_anchors_live`；若要了解人们在搜什么，请使用 `post_dataforseo_keywords_gads_search_volume_live`。💰 上游免费：查询已完成的爬取不产生费用，只有爬取本身计费。

### 计费参考

- 计量方式：按上报的响应成本计量。
- 参考请求估算：0.012 美元。
- 参考客户倍率：1.0。不得对已结算的客户金额再次应用。

仅供参考的元数据，不是账户报价、保证价格或消费上限。资源额度不同于 Felo 额度。最终扣费以 Felo 计费记录为准。

## Base URL

- `https://openapi.felo.ai`

## Authentication

- `FeloBearerAuth` (http bearer, bearer format Felo API Key)
- `FeloApiKey` (apiKey in header `X-API-Key`)

## Request body

Required: **no**

### application/json

Schema:

```json
{
  "type": "array",
  "items": {
    "type": [
      "object",
      "null"
    ],
    "oneOf": [
      {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "<em>任务 ID</em><br><strong>必填字段</strong><br>你可以在 <a href=\"/v3/on_page/task_post/\">Task POST</a> 端点的响应中获取此 ID<br>示例：<br>\"07131248-1535-0216-1000-17384017ad04\""
          },
          "keyword_length": {
            "type": "integer",
            "description": "<em>关键词的词数</em><br><strong>必填字段</strong><br>可选值：<br><code>1</code>、<code>2</code>、<code>3</code>、<code>4</code>、<code>5</code>"
          },
          "url": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>页面 URL</em><br>可选字段<br><strong>如果你不在此处指定页面，将提供整个网站的结果</strong><br>如果使用此字段，API 响应将仅包含指定页面的关键词<br>页面应使用绝对 URL 指定（包含 <code>http://</code> 或 <code>https://</code>）"
          },
          "limit": {
            "type": [
              "integer",
              "null"
            ],
            "description": "<em>返回关键词的最大数量</em><br>可选字段<br>默认值：<code>100</code><br>最大值：<code>1000</code>"
          },
          "filters": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": [
                "object",
                "null"
              ]
            },
            "description": "<em>结果筛选参数数组</em><br>可选字段<br><strong>可同时添加多个筛选条件（最多 8 个）</strong><br>应在条件之间设置逻辑运算符 <code>and</code>、<code>or</code><br>支持以下运算符：<br><code>regex</code>、<code>not_regex</code>、<code>=</code>、<code>&lt;&gt;</code>、<code>in</code>、<code>not_in</code>、<code>like</code>、<code>not_like</code><br>可以将 <code>%</code> 运算符与 <code>like</code> 和 <code>not_like</code> 一起使用，匹配任意长度（零个或多个字符）的字符串<br>示例：<br><code>[\"keyword\",\"=\",\"%seo%\"]</code><p><code>[[\"keyword\",\"=\",\"%seo%\"],<br>\"and\",<br>[\"frequency\",\"&lt;\",\"6\"]]</code><p><code>[[\"keyword\",\"not_like\",\"%seo%\"],<br>\"and\",<br>[[\"frequency\",\"&gt;\",\"6\"],\"or\",[\"density\",\"&gt;\",\"0.02\"]]]</code><p>完整可用筛选器列表请见<a href=\"/v3/on_page/filters_and_thresholds/?bash\" target=\"_blank\" rel=\"noopener noreferrer\">此链接。</a>"
          },
          "order_by": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "description": "<em>结果排序规则</em><br>可选字段<br>你可以使用与 <code>filters</code> 数组相同的值对结果排序<br>可用的排序类型：<br><code>asc</code> - 结果将按升序排列<br><code>desc</code> - 结果将按降序排列<br>应使用逗号设置排序参数<br>示例：<br><code>[\"frequency,desc\"]</code><br><strong>注意，单次请求中最多可设置三条排序规则</strong><br>应使用逗号分隔多条排序规则<br>示例：<br><code>[\"keyword,asc\",\"frequency,desc\"]</code>"
          },
          "tag": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>用户自定义任务标识符</em><br>可选字段<br><em>字符数上限为 255</em><br>可使用此参数标识任务，并将其与结果对应<br>可在响应的 <code>data</code> 对象中找到指定的 <code>tag</code> 值"
          }
        },
        "example": [
          {
            "id": "09101923-1535-0216-0000-2389a8854b70",
            "url": "https://dataforseo.com/",
            "keyword_length": 2,
            "filters": [
              "frequency",
              ">",
              5
            ]
          }
        ]
      }
    ]
  },
  "example": [
    {
      "id": "09101923-1535-0216-0000-2389a8854b70",
      "url": "https://dataforseo.com/",
      "keyword_length": 2,
      "filters": [
        "frequency",
        ">",
        5
      ]
    }
  ]
}
```

## Responses

### 200 — 操作成功

Headers:
- `X-Request-Id` (string) — 联系 Felo 支持时需提供的请求标识符。

**application/json**

Schema: object | null

```json
{
  "type": [
    "object",
    "null"
  ],
  "oneOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityResponseInfo"
    }
  ]
}
```

### 400 — 无法处理该请求。请检查请求参数。

### 401 — 需要有效的 Felo API 密钥。

### 402 — 由于未满足计费要求，请求无法继续。

### 403 — 该账户无权执行此操作。

### 429 — 已达到请求或支出限额。

### 502 — 服务无法完成该请求。

### 503 — API 或计费服务暂时不可用。

### 504 — 服务在处理请求时超时。

### default — 错误响应；上游透传响应可能采用提供方格式

**application/json**

Schema:

```json
{}
```

## Schema definitions

### Response36Afe1097B20_BaseResponseInfo

`#/components/schemas/Response36Afe1097B20_BaseResponseInfo`

```json
{
  "properties": {
    "version": {
      "type": [
        "string",
        "null"
      ],
      "description": "API 的当前版本"
    },
    "status_code": {
      "type": [
        "integer",
        "null"
      ],
      "description": "通用状态码\n完整响应码列表见此处"
    },
    "status_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "通用信息性消息\n完整的一般信息性消息列表见此处"
    },
    "time": {
      "type": [
        "string",
        "null"
      ],
      "description": "总执行时间，秒"
    },
    "cost": {
      "type": [
        "number",
        "null"
      ],
      "description": "任务总费用，美元",
      "format": "double"
    },
    "tasks_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "tasks 数组中的任务数",
      "format": "int64"
    },
    "tasks_error": {
      "type": [
        "integer",
        "null"
      ],
      "description": "tasks 数组中返回错误的任务数",
      "format": "int64"
    }
  }
}
```

### Response36Afe1097B20_BaseResponseTaskInfo

`#/components/schemas/Response36Afe1097B20_BaseResponseTaskInfo`

```json
{
  "properties": {
    "id": {
      "type": [
        "string",
        "null"
      ],
      "description": "任务标识符\n我们系统中 UUID 格式的唯一任务标识符"
    },
    "status_code": {
      "type": [
        "integer",
        "null"
      ],
      "description": "任务的状态码\n由 DataForSEO 生成，范围如下：10000-60000\n完整响应码列表见此处"
    },
    "status_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "任务的信息性消息\n完整的一般信息性消息列表见此处"
    },
    "time": {
      "type": [
        "string",
        "null"
      ],
      "description": "执行时间，秒"
    },
    "cost": {
      "type": [
        "number",
        "null"
      ],
      "description": "任务总费用，美元",
      "format": "double"
    },
    "result_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "result 数组中的元素数",
      "format": "int64"
    },
    "path": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "string",
          "null"
        ]
      },
      "description": "URL 路径"
    },
    "data": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": {
        "type": [
          "object",
          "null"
        ]
      },
      "description": "包含你在 POST 请求中指定的相同参数"
    }
  }
}
```

### Response36Afe1097B20_CrawlStatusInfo

`#/components/schemas/Response36Afe1097B20_CrawlStatusInfo`

```json
{
  "type": "object",
  "properties": {
    "max_crawl_pages": {
      "type": [
        "integer",
        "null"
      ],
      "description": "爬取页面数上限\n 表示设置任务时指定的 max_crawl_pages 限制",
      "format": "int64"
    },
    "pages_in_queue": {
      "type": [
        "integer",
        "null"
      ],
      "description": "当前在爬取队列中的页面数量",
      "format": "int64"
    },
    "pages_crawled": {
      "type": [
        "integer",
        "null"
      ],
      "description": "已爬取的页面数量",
      "format": "int64"
    }
  }
}
```

### Response36Afe1097B20_OnPageKeywordDensityItem

`#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityItem`

```json
{
  "type": "object",
  "properties": {
    "keyword": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>返回的关键词</em>"
    },
    "frequency": {
      "type": [
        "integer",
        "null"
      ],
      "description": "<em>关键词频次</em><br>关键词在网站上（如果指定了 <code>url</code>，则为网页上）出现的次数"
    },
    "density": {
      "type": [
        "number",
        "null"
      ],
      "description": "<em>关键词密度</em><br>按 <code>frequency</code> 与网页或网站上设置了 <code>keyword_length</code> 的关键词总数之比计算"
    }
  }
}
```

### Response36Afe1097B20_OnPageKeywordDensityResponseInfo

`#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityResponseInfo`

```json
{
  "type": "object",
  "allOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_BaseResponseInfo"
    },
    {
      "type": "object",
      "properties": {
        "tasks": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "oneOf": [
              {
                "$ref": "#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityTaskInfo"
              }
            ]
          },
          "description": "<em>任务数组</em>"
        }
      }
    }
  ]
}
```

### Response36Afe1097B20_OnPageKeywordDensityResultInfo

`#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityResultInfo`

```json
{
  "type": "object",
  "properties": {
    "crawl_progress": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>抓取会话的状态</em><br>可能的值：<code>in_progress</code>、<code>finished</code>"
    },
    "crawl_status": {
      "type": [
        "object",
        "null"
      ],
      "oneOf": [
        {
          "$ref": "#/components/schemas/Response36Afe1097B20_CrawlStatusInfo"
        }
      ],
      "description": "<em>抓取会话的详细信息</em>"
    },
    "total_items_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "<em>相关条目的总数</em><br>指定网站或网页上符合所设 <code>keyword_length</code> 和 <code>filters</code> 的关键词总数",
      "format": "int64"
    },
    "items_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "<em>结果数组中的条目数</em>",
      "format": "int64"
    },
    "items": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "object",
          "null"
        ],
        "oneOf": [
          {
            "$ref": "#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityItem"
          }
        ]
      },
      "description": "<em>条目数组</em>"
    }
  }
}
```

### Response36Afe1097B20_OnPageKeywordDensityTaskInfo

`#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityTaskInfo`

```json
{
  "type": "object",
  "allOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_BaseResponseTaskInfo"
    },
    {
      "type": "object",
      "properties": {
        "result": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "oneOf": [
              {
                "$ref": "#/components/schemas/Response36Afe1097B20_OnPageKeywordDensityResultInfo"
              }
            ]
          },
          "description": "<em>结果数组</em>"
        }
      }
    }
  ]
}
```
