
Firecrawl 完整实战指南4 步把任意网站变成 LLM 可用的结构化数据【免费下载链接】firecrawlThe context API to search, scrape, and interact with the web at scale. 项目地址: https://gitcode.com/GitHub_Trending/fi/firecrawlFirecrawl 是一个开源的网页抓取 API一行调用就能把任意网页转成干净的 Markdown 或结构化 JSON代理、限流、JS 渲染这些脏活它替你做。本文按「抓单页 → 找页面 → 结构化 → 上生产」这条完整数据链路带你在 20 行代码内跑通全部 4 步每一步都能单独落地。第 1 步抓单个页面3 行代码拿到 Markdown第一个场景最常见你手里已经有一个 URL想要它的内容喂给大模型。先装 SDK再写 3 行pip install firecrawl-pyfrom firecrawl import Firecrawl app Firecrawl(api_keyfc-YOUR_API_KEY) doc app.scrape(https://docs.firecrawl.dev, formats[markdown]) print(doc.markdown)两个要点formats参数控制输出markdown、html、json、screenshot可任意组合返回的 Markdown 已去掉导航栏、页脚等噪声直接塞进提示词比原始 HTML 省很多 token页面 JS 重、有登录墙它会自动用无头浏览器渲染不用你操心第 2 步先找页面从「一页」扩展到「整站」scrape 只能处理你给定的页面。真实项目里往往是两种情况不知道该抓哪些页或者要抓整个站。Firecrawl 用 3 个调用覆盖这条链路。用 search 全网找页面返回的就是带完整内容的搜索结果results app.search(best AI data tools 2024, limit10)用 map 摸站点结构一个参数就能把整站 URL 列表拉出来再加个关键词可以定向定位links app.map(https://firecrawl.dev) # 全站 URL links app.map(https://firecrawl.dev, searchpricing) # 只找和 pricing 相关的页面用 crawl 整站入库job app.crawl(https://docs.firecrawl.dev, limit50, scrape_options{formats: [markdown]})crawl 是异步任务SDK 会自动等待结果返回你不用自己写轮询。把三步串起来就是一条典型管线map 拿地图 → search 过滤 → 批量 scrape 入库。第 3 步结构化提取定义一个 Schema 直接拿 JSONMarkdown 喂模型方便但数据要进数据库、进下游系统你得的是字段。extract 功能接收一个 JSON Schema返回严格符合 Schema 的数据——你不用写一行正则和选择器。仓库里examples/hacker_news_scraper/firecrawl_scraper.py是最短演示。先用 Pydantic 定义你要什么class NewsItem(BaseModel): title: str Field(descriptionThe title of the news item) upvotes: str Field(descriptionThe number of upvotes) date: str Field(descriptionThe date of the news item)然后抓取 提取就 3 行data app.scrape_url( https://news.ycombinator.com/, params{formats: [extract], extract: {schema: NewsData.model_json_schema()}}, )如果你连 URL 都没有只有一句目标描述用 agent 把整件事交出去result app.agent(promptFind the pricing plans for Notion)agent 会自己搜索、导航、交叉验证返回结构化结果并附来源链接传入 Pydantic 模型时返回的字段与你的模型完全一致。第 4 步上生产定时任务与价格监控让抓取自己跑。examples/blog-articles/scheduling_scrapers/scripts/async_scheduler.py给出了最小循环——抓一次、存 JSON、睡一小时、再抓while True: save_firecrawl_news_data() # 一次完整抓取 保存 JSON await asyncio.sleep(3600) # 每小时循环团队环境里把同一个脚本挂到 GitHub Actions 的 cron 上更规范examples/blog-articles/scheduling_scrapers/下的 notebook 逐步演示了配置过程。一个完整的生产小应用价格监控。examples/blog-articles/amazon-price-tracking/演示了「定期抓商品页 → 存历史价格 → 画趋势图 → 低于阈值告警」全流程跑起来就是这个界面深度研究让 Firecrawl 自己多轮搜索。examples/deep-research-apartment-finder/apartment_finder.py里你输入「旧金山 1 居 2000 美元以下」它自动多轮搜索几分钟最后用 Claude 分析出前 3 个房源含价格、优劣势results firecrawl.deep_research( queryquery, params{maxDepth: 3, timeLimit: 180, maxUrls: 20}, )其中timeLimit和maxUrls两个参数就是成本上限超时强制停、分析页面数封顶。开源还是云。项目核心开源AGPL-3.0按仓库根目录的SELF_HOST.md用 docker compose 即可自托管云版本额外提供 agent 等能力能力速查表能力用法适合谁scrapeapp.scrape(url, formats[markdown])单页转 LLM 上下文searchapp.search(query, limit10)先找页面再抓取mapapp.map(url, search关键词)要站点地图或定位具体页面crawlapp.crawl(url, limit50)整站批量入库extractformats[extract] Schema数据要直接落库agentapp.agent(prompt...)不知道 URL整件事外包deep_researchparams{timeLimit, maxUrls}多轮深度调研从 0 到 13 步跑通第一个 Demo1. 拿到代码git clone https://gitcode.com/GitHub_Trending/fi/firecrawl2. 装 SDK、配密钥pip install firecrawl-py export FIRECRAWL_API_KEYfc-YOUR_API_KEY3. 跑第一次抓取from firecrawl import Firecrawl print(Firecrawl(api_keyfc-YOUR_API_KEY).scrape(https://firecrawl.dev).markdown)卡住时别硬啃文档直接翻examples/目录——每个子目录都是一个可独立运行的小样本从新闻聚合到 CRM 数据回填照着改成你自己的场景就行。Firecrawl 把「从网页拿数据」这件要写 300 行选择器和反爬代码的事压成了 3 行 API 调用——省下的时间值得花在数据本身。【免费下载链接】firecrawlThe context API to search, scrape, and interact with the web at scale. 项目地址: https://gitcode.com/GitHub_Trending/fi/firecrawl创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考