crawlbase文档
登录
notebook 正文通过 iframe 提供

Kaggle 会在 iframe 中渲染已执行的 notebook - 单元格、输出和图表 - 而不是在页面本身中渲染,因此它不属于本响应的一部分。contentUrl 返回该 iframe 的地址;当你需要渲染后的 notebook 时,可将其作为第二次请求获取。该 URL 带有短期有效的签名 token,因此请在抓取后尽快请求,而不要将其存储起来。

API 用法

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

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

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

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/alexisbcook/titanic-tutorial',
  { scraper: 'kaggle-notebook' }
);
const data = JSON.parse(res.body);
require 'crawlbase'
api = Crawlbase::API.new(token: 'YOUR_TOKEN')

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

示例输入 URL

url 参数支持任意 Kaggle notebook 页面 - 即 /code/<author>/<notebook> 的页面。例如:

https://www.kaggle.com/code/alexisbcook/titanic-tutorial
https://www.kaggle.com/code/startupsci/titanic-data-science-solutions
https://www.kaggle.com/code/ldfreeman3/a-data-science-framework-to-achieve-99-accuracy

响应结构

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

url
string
被抓取的 notebook 页面的 URL。
slug
string | null
notebook 标识符,形式为 author/notebook,从 URL 路径中读取。
title
string | null
notebook 显示标题。
author
object
拥有该 notebook 的账号。
author.username
string | null
所有者账号名。
author.name
string | null
所有者显示名称。
author.url
string | null
所有者资料页的绝对 URL。
publishedAt
string | null
首次发布的 ISO 8601 时间戳。
lastUpdated
string | null
最新版本的 ISO 8601 时间戳。
thumbnail
string | null
notebook 卡片图片的 URL。
language
string | null
notebook 使用的语言(例如 PythonR)。
runtime
string | null
按页面显示的最近一次运行的执行时长,含单位(例如 16s)。
version
integer | null
当前显示的版本号。
versionCount
integer | null
已发布版本的总数。
views
integer | null
页面总浏览次数。
votes
integer | null
点赞数。
copies
integer | null
该 notebook 被复制或 fork 的次数。
commentCount
integer | null
该 notebook 上的评论数量。
medal
string | null
该 notebook 获得的 Kaggle 奖牌(例如 gold),没有奖牌时为 null。
license
object
该 notebook 发布所采用的许可证。
license.name
string | null
许可证显示名称(例如 Apache 2.0)。
license.url
string | null
许可证文本的规范 URL。
inputs
array
作为输入关联的竞赛、数据集和其他 notebook。
inputs[].category
string | null
Kaggle 标注的输入分组标题(例如 COMPETITIONS)。
inputs[].title
string | null
所关联输入的显示名称。
contentUrl
string | null
承载渲染后 notebook 正文的 iframe 地址。带有短期有效的签名 token。

示例响应

{
  "url": "https://www.kaggle.com/code/alexisbcook/titanic-tutorial",
  "slug": "alexisbcook/titanic-tutorial",
  "title": "Titanic Tutorial",
  "author": {
    "username": "alexisbcook",
    "name": "Alexis Cook",
    "url": "https://www.kaggle.com/alexisbcook"
  },
  "publishedAt": "2022-06-24T00:25:16.1066667Z",
  "lastUpdated": "2022-06-24T00:25:16.1066667Z",
  "thumbnail": "https://storage.googleapis.com/kaggle-avatars/thumbnails/2603295-kg.jpg",
  "language": "Python",
  "runtime": "16s",
  "version": 22,
  "versionCount": 22,
  "views": 3265744,
  "votes": 60135,
  "copies": 51320,
  "commentCount": 30626,
  "medal": "gold",
  "license": {
    "name": "Apache 2.0",
    "url": "http://www.apache.org/licenses/LICENSE-2.0"
  },
  "inputs": [
    {
      "category": "COMPETITIONS",
      "title": "Titanic - Machine Learning from Disaster"
    }
  ],
  "contentUrl": "https://www.kaggleusercontent.com/kf/99170538//__results__.html"
}