GitHub SERP
将 GitHub 仓库搜索结果页解析为结构化的仓库数组,包含 stars、语言、主题和分页信息。
API 用法
在 Crawling API 请求中添加 &scraper=github-serp。在 url 参数中对目标 URL 进行 URL 编码。一次请求返回一页;沿着 pagination.next_page_url 继续翻页,直至 GitHub 的 1000 条结果上限。
curl 'https://api.crawlbase.com/?token=YOUR_TOKEN' \
--data-urlencode 'url=https://github.com/search?q=web+scraping&type=repositories' \
--data-urlencode 'scraper=github-serp' -Gfrom crawlbase import CrawlingAPI
api = CrawlingAPI({'token': 'YOUR_TOKEN'})
res = api.get(
'https://github.com/search?q=web+scraping&type=repositories',
{'scraper': 'github-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://github.com/search?q=web+scraping&type=repositories',
{ scraper: 'github-serp' }
);
const data = JSON.parse(res.body);require 'crawlbase'
api = Crawlbase::API.new(token: 'YOUR_TOKEN')
res = api.get('https://github.com/search?q=web+scraping&type=repositories', scraper: 'github-serp')
data = JSON.parse(res.body)示例输入 URL
传入 url 参数的 URL(为便于阅读已 URL 解码):
https://github.com/search?q=web+scraping&type=repositories响应结构
JSON 响应体。当源页面省略对应值时,字段类型可能为 null。
产生这些结果的搜索查询。
搜索类型,例如
repositories。排序字段,例如
stars。按最佳匹配排序时不存在。排序方向,
desc 或 asc。所有页面报告的结果总数。
当前页码。
用于遍历结果集的分页信息。
当前页码。
GitHub 为此查询暴露的最大页码。
下一页的绝对 URL,或在最后一页 / 结果上限处为
null。上一页的绝对 URL,或在第一页时为
null。当存在低于 1000 条结果上限的下一页时为 true。
每个仓库的结果(见下方字段)。
结果在本页中的排名(从 1 开始)。
仓库名称。
所有者(用户或组织)登录名。
完整的
owner/name 标识符。绝对的仓库 URL。
仓库描述。
主要编程语言。
Star 数量。
结果卡片上显示的主题标签。
存在时,最后更新的时间戳或相对标签。
存在时,结果卡片上显示的许可证。
如果仓库是公开归档则为 true。
如果所有者可被赞助则为 true。
示例响应
{
"query": "web scraping",
"searchType": "repositories",
"sort": "stars",
"order": "desc",
"totalResults": 133816,
"currentPage": 1,
"pagination": {
"current_page": 1,
"total_pages": 100,
"next_page_url": "https://github.com/search?q=web+scraping&type=repositories&s=stars&o=desc&p=2",
"previous_page_url": null,
"has_next": true
},
"results": [
{
"position": 1,
"name": "scrapy",
"owner": "scrapy",
"fullName": "scrapy/scrapy",
"url": "https://github.com/scrapy/scrapy",
"description": "Scrapy, a fast high-level web crawling & scraping framework for Python.",
"primaryLanguage": "Python",
"stars": 63119,
"topics": ["python", "crawler", "framework", "scraping", "crawling"],
"updatedAt": null,
"license": null,
"archived": false,
"sponsorable": false
}
]
}