> ## Documentation Index
> Fetch the complete documentation index at: https://docs.olostep.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 地图

> 获取网站上的所有URL。

通过Olostep的`/v1/maps`端点，你可以获取网站上的所有URL。这对于内容发现、网站结构分析（例如SEO）或决定下一个要抓取的URL非常有用。

* 获取网站上的所有URL（包括站点地图和发现的链接）
* 使用特殊模式包含/排除路径（例如`/blog/**`）
* 使用`cursor`分页处理大型响应（每个响应最多10MB）
* 使用`top_n`限制数量

有关API详细信息，请参阅[地图端点API参考](/api-reference/maps/create)。

## 安装

<CodeGroup>
  ```python Python theme={null}
  pip install olostep
  ```

  ```javascript Node theme={null}
  npm install olostep
  ```

  ```bash cURL theme={null}
  # curl在macOS、Linux和Windows上默认可用
  ```

  ```javascript Node (API) theme={null}
  npm install node-fetch
  ```

  ```bash Python (API) theme={null}
  pip install requests
  ```
</CodeGroup>

## 使用方法

发送一个包含网站`url`的POST请求。可以选择传递`include_urls`、`exclude_urls`（glob模式）和`top_n`。

<CodeGroup>
  ```python Python theme={null}
  from olostep import Olostep

  client = Olostep(api_key="YOUR_REAL_KEY")

  sitemap = client.maps.create(url="https://docs.olostep.com")

  for url in sitemap.urls():
      print(url)
  ```

  ```js Node theme={null}
  import Olostep from 'olostep'

  const client = new Olostep({ apiKey: 'YOUR_REAL_KEY' })

  const map = await client.maps.create({ url: 'https://docs.olostep.com' })

  for await (const url of map.urls()) {
    console.log(url)
  }
  ```

  ```bash cURL theme={null}
  curl -s -X POST "https://api.olostep.com/v1/maps" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://docs.olostep.com"
    }'
  ```

  ```js Node (API) theme={null}
  const res = await fetch('https://api.olostep.com/v1/maps', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <YOUR_API_KEY>',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ url: 'https://docs.olostep.com' })
  })
  console.log(await res.json())
  ```

  ```python Python (API) theme={null}
  import requests
  import json

  endpoint = "https://api.olostep.com/v1/maps"

  payload = {
      "url": "https://docs.olostep.com"
  }
  headers = {
      "Authorization": "Bearer <YOUR_API_KEY>",
      "Content-Type": "application/json"
  }

  response = requests.post(endpoint, json=payload, headers=headers)
  print(json.dumps(response.json(), indent=2))
  ```
</CodeGroup>

响应时间通常在几秒钟内，但对于更复杂的网站可能需要长达120秒。它可以从网站中提取所有URL，甚至是反向链接和不在站点地图中的链接。你还可以决定要在响应中包含或排除的URL路径。

默认情况下，端点在一次调用中返回大约10万个URL（最大10MB）。如果响应包含更多数据，API会返回一个`cursor`参数，可用于分页和获取后续的URL。有关更多详细信息，请参阅[API参考](/api-reference/maps/create#body-cursor)。

此端点特别有用，当你需要：

* 发现网站上的所有内容页面
* 分析网站结构和层次
* 为批处理准备URL
* 决定要抓取的特定URL

为了更精细地控制返回的URL，你可以使用参数`include_urls`和`exclude_urls`。

### 示例

假设你想从www\.brex.com提取所有路径在`/product/`之后的URL，例如`https://www.brex.com/product/api/no-code`，但也包括`www.brex.com/product`。你可以使用以下代码：

<CodeGroup>
  ```python Python theme={null}
  from olostep import Olostep

  client = Olostep(api_key="YOUR_REAL_KEY")

  sitemap = client.maps.create(
      url="https://www.brex.com/",
      include_urls=["/product", "/product/**"],
      top_n=100000,
  )

  for url in sitemap.urls():
      print(url)
  ```

  ```js Node theme={null}
  import Olostep from 'olostep'

  const client = new Olostep({ apiKey: 'YOUR_REAL_KEY' })

  const map = await client.maps.create({
    url: 'https://www.brex.com/',
    includeUrls: ['/product', '/product/**'],
    topN: 100000,
  })

  for await (const url of map.urls()) {
    console.log(url)
  }
  ```

  ```bash cURL theme={null}
  curl -s -X POST "https://api.olostep.com/v1/maps" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://www.brex.com/",
      "include_urls": ["/product", "/product/**"],
      "top_n": 100000
    }'
  ```

  ```js Node (API) theme={null}
  const endpoint = 'https://api.olostep.com/v1/maps'

  const res = await fetch(endpoint, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <YOUR_API_KEY>',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'https://www.brex.com/',
      include_urls: ['/product', '/product/**'],
      top_n: 100000
    })
  })
  console.log(await res.text())
  ```

  ```python Python (API) theme={null}
  import requests

  endpoint = "https://api.olostep.com/v1/maps"

  payload = {
      "url": "https://www.brex.com/",
      "include_urls": ["/product", "/product/**"],
      "top_n": 100000
  }

  headers = {
      "Authorization": "Bearer <YOUR_API_KEY>",
      "Content-Type": "application/json"
  }

  response = requests.post(endpoint, json=payload, headers=headers)

  print(response.text)
  ```
</CodeGroup>

## 结论

地图端点是内容发现和网站分析的强大工具。它提供了网站上URL的全面列表，使你能够从特定页面提取内容或分析网站结构。此端点对需要分析网站内容或结构的SEO专业人士、内容营销人员、AI代理特别有用。

## 价格

地图费用为1个信用点。然后对于响应中返回的每额外1000个URL，将收取额外的信用点。
