crawlbase文档
登录

API 用法

Crawling API 请求中添加 &scraper=exercism-exercise。在 url 参数中对目标 URL 进行 URL 编码。

curl 'https://api.crawlbase.com/?token=YOUR_TOKEN' \
  --data-urlencode 'url=https://exercism.org/tracks/ruby/exercises/two-fer' \
  --data-urlencode 'scraper=exercism-exercise' -G
from crawlbase import CrawlingAPI

api = CrawlingAPI({'token': 'YOUR_TOKEN'})
res = api.get(
    'https://exercism.org/tracks/ruby/exercises/two-fer',
    {'scraper': 'exercism-exercise'}
)

import json
data = json.loads(res['body'])
const { CrawlingAPI } = require('crawlbase');
const api = new CrawlingAPI({ token: 'YOUR_TOKEN' });

const res = await api.get(
  'https://exercism.org/tracks/ruby/exercises/two-fer',
  { scraper: 'exercism-exercise' }
);
const data = JSON.parse(res.body);
require 'crawlbase'
api = Crawlbase::API.new(token: 'YOUR_TOKEN')

res = api.get('https://exercism.org/tracks/ruby/exercises/two-fer', scraper: 'exercism-exercise')
data = JSON.parse(res.body)

示例输入 URL

url 参数支持任意 Exercism 练习概览页面 - 即 /tracks/<track>/exercises/<slug> 的页面。例如:

https://exercism.org/tracks/ruby/exercises/two-fer
https://exercism.org/tracks/python/exercises/leap
https://exercism.org/tracks/go/exercises/hello-world
https://exercism.org/tracks/rust/exercises/grains

响应结构

JSON 响应体。当源页面省略对应值时,字段类型可能为 null

url
string
被抓取的练习页面的 URL。
track
string | null
从 URL 路径读取的轨道 slug(例如 ruby),无法确定时为 null。
slug
string | null
从 URL 路径读取的练习 slug(例如 two-fer),无法确定时为 null。
title
string | null
练习显示标题。
difficulty
string | null
难度标签(例如 easymediumhard)。
instructions
string | null
以纯文本呈现的完整练习说明,空白字符已折叠。
instructionsHtml
string | null
以 HTML 呈现的完整练习说明,保留标题、代码块和列表。

示例响应

{
  "url": "https://exercism.org/tracks/ruby/exercises/two-fer",
  "track": "ruby",
  "slug": "two-fer",
  "title": "Two Fer",
  "difficulty": "easy",
  "instructions": "Two Fer Two-fer is short for two for one. One for you and one for me. Given a name, return a string with the message: One for name, one for me. Where \"name\" is the given name. However, if the name is missing, return the string: One for you, one for me.",
  "instructionsHtml": "

Instructions

\n

Two-fer is short for two for one. One for you and one for me.

\n

Given a name, return a string with the message:

\n
One for name, one for me.
" }