crawlbase文档
登录
列表页面未公开的内容

Kaggle 只把结果总数标注为 Results (100+),因此 totalCountLabel 会原样以字符串返回,而不会转换为数字。作者多于一人的行会渲染为堆叠头像,文档中没有图片 URL,因此这些行的 author.image 为空。关联多个竞赛的 notebook 只显示第一个竞赛,外加一个 +2 角标 - 其余名称并不在页面中,因此只能给出 additionalContextCount

API 用法

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

curl 'https://api.crawlbase.com/?token=YOUR_TOKEN' \
  --data-urlencode 'url=https://www.kaggle.com/code?searchQuery=titanic' \
  --data-urlencode 'scraper=kaggle-notebook-serp' -G
from crawlbase import CrawlingAPI

api = CrawlingAPI({'token': 'YOUR_TOKEN'})
res = api.get(
    'https://www.kaggle.com/code?searchQuery=titanic',
    {'scraper': 'kaggle-notebook-serp'}
)

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

const res = await api.get(
  'https://www.kaggle.com/code?searchQuery=titanic',
  { scraper: 'kaggle-notebook-serp' }
);
const data = JSON.parse(res.body);
require 'crawlbase'
api = Crawlbase::API.new(token: 'YOUR_TOKEN')

res = api.get('https://www.kaggle.com/code?searchQuery=titanic', scraper: 'kaggle-notebook-serp')
data = JSON.parse(res.body)

示例输入 URL

url 参数支持任意 Kaggle notebook 搜索或列表页面 - 即 /code 的页面,带或不带查询字符串均可。例如:

https://www.kaggle.com/code?searchQuery=titanic
https://www.kaggle.com/code?searchQuery=xgboost&language=Python
https://www.kaggle.com/code
https://www.kaggle.com/code?searchQuery=nlp&page=2

响应结构

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

url
string
被抓取的搜索页面的 URL。
query
string | null
从请求 URL 中读取的搜索词。Kaggle 在该页面上渲染的搜索框为空,因此 URL 是唯一来源。
totalCountLabel
string | null
Kaggle 标注的结果总数,原样返回,例如 100+。由于页面未给出精确数字,该值以字符串形式返回。
page
integer | null
当前页码,无法确定时为 null。
hasNextPage
boolean
是否还有下一页结果。
resultCount
integer
本页返回的行数。
results
array
notebook 行,按其在页面上出现的顺序排列。
results[].position
integer
该行在本页中的排名,从 1 开始。
results[].title
string | null
notebook 显示标题。
results[].url
string | null
notebook 的绝对 URL。
results[].slug
string | null
notebook 标识符,形式为 author/notebook,从 URL 路径中读取。
results[].author
object
拥有该 notebook 的账号。
results[].author.username
string | null
所有者账号名,取自 notebook URL 的第一个路径段,因此在存在共同作者的行上同样可以解析。
results[].author.name
string | null
所有者显示名称。
results[].author.url
string | null
所有者资料页的绝对 URL。
results[].author.image
string | null
所有者头像的 URL。在存在共同作者的行上为空,因为 Kaggle 会渲染堆叠头像,文档中没有 URL。
results[].coauthors
array
其余作者的显示名称,以字符串数组形式返回。单作者 notebook 上为空。
results[].lastUpdated
string | null
notebook 最近一次更新的绝对时间戳。卡片只显示相对时间,因此该值取自其背后的提示框,并保留 Kaggle 的格式而非 ISO 8601。
results[].commentCount
integer | null
该 notebook 上的评论数量。
results[].context
string | null
该 notebook 所关联的竞赛或数据集的名称。
results[].additionalContextCount
integer
context 之外,该 notebook 还关联了多少个竞赛或数据集。它们的名称不在页面中,因此只能给出数量。
results[].votes
integer | null
该 notebook 的点赞数。
results[].medal
string | null
该 notebook 获得的 Kaggle 奖牌(例如 gold),该行没有奖牌时为 null。

示例响应

{
  "url": "https://www.kaggle.com/code?searchQuery=titanic",
  "query": "titanic",
  "totalCountLabel": "100+",
  "page": 1,
  "hasNextPage": true,
  "resultCount": 20,
  "results": [
    {
      "position": 1,
      "title": "Titanic Tutorial",
      "url": "https://www.kaggle.com/code/alexisbcook/titanic-tutorial",
      "slug": "alexisbcook/titanic-tutorial",
      "author": {
        "username": "alexisbcook",
        "name": "Alexis Cook",
        "url": "https://www.kaggle.com/alexisbcook",
        "image": "https://storage.googleapis.com/kaggle-avatars/thumbnails/2603295-kg.jpg"
      },
      "coauthors": [],
      "lastUpdated": "Fri Jun 24 2022 00:25:16 GMT+0000 (Coordinated Universal Time)",
      "commentCount": 30626,
      "context": "Titanic - Machine Learning from Disaster",
      "additionalContextCount": 0,
      "votes": 60135,
      "medal": "gold"
    },
    {
      "position": 3,
      "title": "Spaceship Titanic with TFDF",
      "url": "https://www.kaggle.com/code/gusthema/spaceship-titanic-with-tfdf",
      "slug": "gusthema/spaceship-titanic-with-tfdf",
      "author": {
        "username": "gusthema",
        "name": "Gusthema",
        "url": "https://www.kaggle.com/gusthema",
        "image": ""
      },
      "coauthors": [
        "Nidhin PD"
      ],
      "lastUpdated": "Mon Apr 17 2023 09:36:29 GMT+0000 (Coordinated Universal Time)",
      "commentCount": 378,
      "context": "Spaceship Titanic",
      "additionalContextCount": 0,
      "votes": 7863,
      "medal": "gold"
    },
    {
      "position": 10,
      "title": "Titanic Top Solution",
      "url": "https://www.kaggle.com/code/brendan45774/titanic-top-solution",
      "slug": "brendan45774/titanic-top-solution",
      "author": {
        "username": "brendan45774",
        "name": "Brenda N",
        "url": "https://www.kaggle.com/brendan45774",
        "image": "https://storage.googleapis.com/kaggle-avatars/thumbnails/2681031-kg.jpg"
      },
      "coauthors": [],
      "lastUpdated": "Wed Sep 01 2021 16:03:11 GMT+0000 (Coordinated Universal Time)",
      "commentCount": 249,
      "context": "Titanic - Machine Learning from Disaster",
      "additionalContextCount": 2,
      "votes": 2294,
      "medal": "gold"
    }
  ]
}