Kaggle Notebook Search
将 Kaggle notebook 搜索或列表页面解析为结构化 JSON,每个 notebook 一行,包含作者、共同作者、竞赛上下文、点赞数和评论数。
列表页面未公开的内容
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' -Gfrom 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。
从请求 URL 中读取的搜索词。Kaggle 在该页面上渲染的搜索框为空,因此 URL 是唯一来源。
Kaggle 标注的结果总数,原样返回,例如
100+。由于页面未给出精确数字,该值以字符串形式返回。当前页码,无法确定时为 null。
是否还有下一页结果。
本页返回的行数。
notebook 行,按其在页面上出现的顺序排列。
该行在本页中的排名,从 1 开始。
notebook 显示标题。
notebook 的绝对 URL。
notebook 标识符,形式为
author/notebook,从 URL 路径中读取。拥有该 notebook 的账号。
所有者账号名,取自 notebook URL 的第一个路径段,因此在存在共同作者的行上同样可以解析。
所有者显示名称。
所有者资料页的绝对 URL。
所有者头像的 URL。在存在共同作者的行上为空,因为 Kaggle 会渲染堆叠头像,文档中没有 URL。
其余作者的显示名称,以字符串数组形式返回。单作者 notebook 上为空。
notebook 最近一次更新的绝对时间戳。卡片只显示相对时间,因此该值取自其背后的提示框,并保留 Kaggle 的格式而非 ISO 8601。
该 notebook 上的评论数量。
该 notebook 所关联的竞赛或数据集的名称。
除
context 之外,该 notebook 还关联了多少个竞赛或数据集。它们的名称不在页面中,因此只能给出数量。该 notebook 的点赞数。
该 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"
}
]
}