登录

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' -G
from 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

query
string | null
产生这些结果的搜索查询。
searchType
string | null
搜索类型,例如 repositories
sort
string | null
排序字段,例如 stars。按最佳匹配排序时不存在。
order
string | null
排序方向,descasc
totalResults
integer | null
所有页面报告的结果总数。
currentPage
integer
当前页码。
pagination
object
用于遍历结果集的分页信息。
pagination.current_page
integer
当前页码。
pagination.total_pages
integer | null
GitHub 为此查询暴露的最大页码。
pagination.next_page_url
string | null
下一页的绝对 URL,或在最后一页 / 结果上限处为 null
pagination.previous_page_url
string | null
上一页的绝对 URL,或在第一页时为 null
pagination.has_next
boolean
当存在低于 1000 条结果上限的下一页时为 true。
results
array
每个仓库的结果(见下方字段)。
results[].position
integer
结果在本页中的排名(从 1 开始)。
results[].name
string | null
仓库名称。
results[].owner
string | null
所有者(用户或组织)登录名。
results[].fullName
string
完整的 owner/name 标识符。
results[].url
string
绝对的仓库 URL。
results[].description
string | null
仓库描述。
results[].primaryLanguage
string | null
主要编程语言。
results[].stars
integer | null
Star 数量。
results[].topics
array
结果卡片上显示的主题标签。
results[].updatedAt
string | null
存在时,最后更新的时间戳或相对标签。
results[].license
string | null
存在时,结果卡片上显示的许可证。
results[].archived
boolean
如果仓库是公开归档则为 true。
results[].sponsorable
boolean
如果所有者可被赞助则为 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
    }
  ]
}