Skip to content
Firecrawl Docs
Firecrawl Docs
常见站点

抓取 GitHub

了解如何使用 Firecrawl 的核心功能和研究索引抓取和搜索 GitHub

了解如何使用 Firecrawl 的核心功能抓取 GitHub 仓库、issue和文档。

使用 Firecrawl 获取 GitHub 数据有两种方式。你可以抓取、映射或爬取特定的 github.com URL (本页其余内容将介绍此方法) ,也可以使用 研究索引 的 GitHub 搜索,无需知道确切 URL,即可通过语义搜索发现 GitHub 上相关的issue、拉取请求、讨论和 README。

npm install firecrawl zod

通过 Zod schema 从仓库中提取结构化数据。

import { Firecrawl } from 'firecrawl';
import { z } from 'zod';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const result = await firecrawl.scrape('https://github.com/firecrawl/firecrawl', {
    formats: [{
        type: 'json',
        schema: z.object({
            name: z.string(),
            description: z.string(),
            stars: z.number(),
            forks: z.number(),
            language: z.string(),
            topics: z.array(z.string())
        })
    }]
});

console.log(result.json);

搜索 GitHub 上的仓库、issue 或文档。

import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const searchResult = await firecrawl.search('machine learning site:github.com', {
    limit: 10,
    sources: [{ type: 'web' }], // { type: 'news' }, { type: 'images' }
    scrapeOptions: {
        formats: ['markdown']
    }
});

console.log(searchResult);

Firecrawl 的 研究索引包含 GitHub 索引,可对已索引的公开 GitHub Issue、拉取请求、讨论和仓库 README 进行语义搜索。当你不清楚具体的仓库或 URL 时,它可帮助你查找实现细节和既有工程实践。

import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const results = await firecrawl.research.searchGithub(
    'how to handle rate limit retries with exponential backoff',
    { k: 10 }
);

console.log(results);

您也可以通过通用的 /search 端点,将类别指定为 github,访问同一 GitHub 索引。

import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const searchResult = await firecrawl.search('exponential backoff retry', {
    categories: ['github'],
    limit: 10
});

console.log(searchResult);

请参见 研究索引指南,了解如何使用 Python、cURL、CLI 和 MCP。

抓取单个 GitHub 页面 (仓库、issue 或文件) 。

import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const result = await firecrawl.scrape('https://github.com/firecrawl/firecrawl', {
    formats: ['markdown'] // 例如 html、links 等
});

console.log(result);

发现仓库或文档站点中所有可用的 URL。请注意:Map 仅返回 URL,不包含页面内容。

import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const mapResult = await firecrawl.map('https://github.com/vercel/next.js/tree/canary/docs');

console.log(mapResult.links);
// 返回不含内容的 URL 数组

从仓库或文档中抓取多个页面。

import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const crawlResult = await firecrawl.crawl('https://github.com/facebook/react/wiki', {
    limit: 10,
    scrapeOptions: {
        formats: ['markdown']
    }
});

console.log(crawlResult.data);

同时抓取多个 GitHub 链接。

import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

// 等待完成
const job = await firecrawl.batchScrape([
    'https://github.com/vercel/next.js',
    'https://github.com/facebook/react',
    'https://github.com/microsoft/typescript'],
    {
        options: {
            formats: ['markdown']
        },
        pollInterval: 2,
        timeout: 120
    }
);


console.log(job.status, job.completed, job.total);

console.log(job);

一次性从多个仓库中抽取结构化数据。

import { Firecrawl } from 'firecrawl';
import { z } from 'zod';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

// 等待完成
const job = await firecrawl.batchScrape([
    'https://github.com/vercel/next.js',
    'https://github.com/facebook/react'],
    {
        options: {
            formats: [{
                type: 'json',
                schema: z.object({
                    name: z.string(),
                    description: z.string(),
                    stars: z.number(),
                    language: z.string()
                })
            }]
        },
        pollInterval: 2,
        timeout: 120
    }
);


console.log(job.status, job.completed, job.total);

console.log(job);
Was this page helpful?Suggest editsRaise issue