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.
通过 Olostep 的 /v1/crawls 端点,你可以抓取一个网站并获取所有页面的内容。
- 抓取一个网站并获取所有子页面的内容(或限制抓取深度)
- 使用特殊模式抓取特定页面(例如
/blog/**)
- 传递一个
webhook_url,在抓取完成时收到通知
- 搜索查询仅查找特定页面并按相关性排序
有关API详情,请参阅 抓取端点API参考。
开始抓取
提供起始URL,包含/排除URL模式,以及 max_pages。可选项:max_depth,include_external,include_subdomain,search_query,top_n,webhook_url,timeout。
from olostep import Olostep
client = Olostep(api_key="YOUR_REAL_KEY")
crawl = client.crawls.create(
start_url="https://olostep.com",
max_pages=100,
include_urls=["/**"],
exclude_urls=["/collections/**"],
include_external=False,
)
print(crawl.id, crawl.status)
由于 Olostep 中的所有内容都是对象,你将收到一个 crawl 对象作为响应。crawl 对象有一些属性,比如 id 和 status,你可以用来跟踪抓取。
检查抓取状态
轮询抓取以跟踪进度,直到 status 为 completed。
# 使用上一步的抓取对象
info = crawl.info()
print(info.status, info.pages_count)
# 或者等待完成
crawl.wait_till_done(check_every_n_secs=5)
或者,你可以在开始抓取时传递一个 webhook_url,以便在抓取完成时收到通知。
列出页面(使用游标分页/流)
获取页面并使用 cursor 和 limit 进行迭代。适用于抓取 in_progress 或 completed 状态。
# 迭代所有页面(自动等待抓取完成,处理分页)
for page in crawl.pages():
print(page.url, page.retrieve_id)
搜索查询(限制到前 N 个相关)
在开始时使用 search_query,并可选择使用 search_query 过滤列表。使用 top_n 限制每页探索。
from olostep import Olostep
client = Olostep(api_key="YOUR_REAL_KEY")
crawl = client.crawls.create(
start_url="https://olostep.com",
max_pages=100,
include_urls=["/**"],
search_query="contact us",
top_n=5,
)
for page in crawl.pages(search_query="contact us"):
print(page.url)
获取内容
使用每个页面的 retrieve_id 和 /v1/retrieve 来获取 html_content 和/或 markdown_content。
# 获取每个抓取页面的内容
for page in crawl.pages():
content = page.retrieve(["markdown"])
print(content.markdown_content)
注意事项
- 分页是基于游标的;重复请求直到
cursor 不存在。
/v1/crawls/{crawl_id}/pages 上的内容字段已弃用;请使用 /v1/retrieve。
- Webhooks:设置
webhook_url 以在抓取完成时接收POST。
抓取每个页面消耗1个信用。