代码示例
¥Code Examples
本页面提供了完整的示例脚本列表,用于演示 Crawl4AI 的各种特性和功能。每个示例都旨在展示特定的功能,以便您更轻松地了解如何在自己的项目中实现这些功能。
¥This page provides a comprehensive list of example scripts that demonstrate various features and capabilities of Crawl4AI. Each example is designed to showcase specific functionality, making it easier for you to understand how to implement these features in your own projects.
入门示例
¥Getting Started Examples
¥Example
¥Description
¥Link
¥Hello World
¥A simple introductory example demonstrating basic usage of AsyncWebCrawler with JavaScript execution and content filtering.
¥Quickstart
¥A comprehensive collection of examples showcasing various features including basic crawling, content cleaning, link analysis, JavaScript execution, CSS selectors, media handling, custom hooks, proxy configuration, screenshots, and multiple extraction strategies.
¥Quickstart Set 1
¥Basic examples for getting started with Crawl4AI.
¥Quickstart Set 2
¥More advanced examples for working with Crawl4AI.
| 例子 | 描述 | 关联 |
|---|---|---|
| 你好世界 | 一个简单的介绍性示例,演示了 AsyncWebCrawler 的基本用法,包括 JavaScript 执行和内容过滤。 | 查看代码 |
| 快速入门 | 全面的示例集合,展示各种功能,包括基本爬取、内容清理、链接分析、JavaScript 执行、CSS 选择器、媒体处理、自定义挂钩、代理配置、屏幕截图和多种提取策略。 | 查看代码 |
| 快速入门套装 1 | 开始使用 Crawl4AI 的基本示例。 | 查看代码 |
| 快速入门套装 2 | 使用 Crawl4AI 的更多高级示例。 | 查看代码 |
浏览器和爬取功能
¥Browser & Crawling Features
¥Example
¥Description
¥Link
¥Built-in Browser
¥Demonstrates how to use the built-in browser capabilities.
¥Browser Optimization
¥Focuses on browser performance optimization techniques.
¥arun vs arun_many
¥Compares the arun and arun_many methods for single vs. multiple URL crawling.
¥Multiple URLs
¥Shows how to crawl multiple URLs asynchronously.
¥Page Interaction
¥Guide on interacting with dynamic elements through clicks.
¥Crawler Monitor
¥Shows how to monitor the crawler's activities and status.
¥Full Page Screenshot & PDF
¥Guide on capturing full-page screenshots and PDFs from massive webpages.
| 例子 | 描述 | 关联 |
|---|---|---|
| 内置浏览器 | 演示如何使用内置浏览器功能。 | 查看代码 |
| 浏览器优化 | 专注于浏览器性能优化技术。 | 查看代码 |
| arun 与 arun_many | 比较arun和arun_many单个与多个 URL 抓取的方法。 |
查看代码 |
| 多个 URL | 展示如何异步抓取多个 URL。 | 查看代码 |
| 页面交互 | 通过点击与动态元素进行交互的指南。 | 查看指南 |
| 爬虫监控器 | 展示如何监控爬虫的活动和状态。 | 查看代码 |
| 整页截图和 PDF | 从大量网页中捕获整页截图和 PDF 的指南。 | 查看指南 |
高级爬行和深度爬行
¥Advanced Crawling & Deep Crawling
¥Example
¥Description
¥Link
¥Deep Crawling
¥An extensive tutorial on deep crawling capabilities, demonstrating BFS and BestFirst strategies, stream vs. non-stream execution, filters, scorers, and advanced configurations.
¥Virtual Scroll
¥Comprehensive examples for handling virtualized scrolling on sites like Twitter, Instagram. Demonstrates different scrolling scenarios with local test server.
¥Adaptive Crawling
¥Demonstrates intelligent crawling that automatically determines when sufficient information has been gathered.
¥Dispatcher
¥Shows how to use the crawl dispatcher for advanced workload management.
¥Storage State
¥Tutorial on managing browser storage state for persistence.
¥Network Console Capture
¥Demonstrates how to capture and analyze network requests and console logs.
| 例子 | 描述 | 关联 |
|---|---|---|
| 深度爬行 | 关于深度爬行功能的广泛教程,演示了 BFS 和 BestFirst 策略、流与非流执行、过滤器、评分器和高级配置。 | 查看代码 |
| 虚拟卷轴 | 处理 Twitter、Instagram 等网站上虚拟化滚动的综合示例。使用本地测试服务器演示不同的滚动场景。 | 查看代码 |
| 自适应爬行 | 演示智能爬取,自动确定何时已收集到足够的信息。 | 查看代码 |
| 调度员 | 展示如何使用爬网调度程序进行高级工作负载管理。 | 查看代码 |
| 存储状态 | 关于管理浏览器存储状态以实现持久性的教程。 | 查看指南 |
| 网络控制台捕获 | 演示如何捕获和分析网络请求和控制台日志。 | 查看代码 |
提取策略
¥Extraction Strategies
¥Example
¥Description
¥Link
¥Extraction Strategies
¥Demonstrates different extraction strategies with various input formats (markdown, HTML, fit_markdown) and JSON-based extractors (CSS and XPath).
¥Scraping Strategies
¥Compares the performance of different scraping strategies.
¥LLM Extraction
¥Demonstrates LLM-based extraction specifically for OpenAI pricing data.
¥LLM Markdown
¥Shows how to use LLMs to generate markdown from crawled content.
¥Summarize Page
¥Shows how to summarize web page content.
| 例子 | 描述 | 关联 |
|---|---|---|
| 提取策略 | 演示具有各种输入格式(markdown、HTML、fit_markdown)和基于 JSON 的提取器(CSS 和 XPath)的不同提取策略。 | 查看代码 |
| 抓取策略 | 比较不同抓取策略的性能。 | 查看代码 |
| 法学硕士 (LLM) 提取 | 演示专门针对 OpenAI 定价数据的基于 LLM 的提取。 | 查看代码 |
| LLM Markdown | 展示如何使用 LLM 从抓取的内容生成 markdown。 | 查看代码 |
| 摘要页面 | 展示如何总结网页内容。 | 查看代码 |
电子商务和专业爬虫
¥E-commerce & Specialized Crawling
¥Example
¥Description
¥Link
¥Amazon Product Extraction
¥Demonstrates how to extract structured product data from Amazon search results using CSS selectors.
¥Amazon with Hooks
¥Shows how to use hooks with Amazon product extraction.
¥Amazon with JavaScript
¥Demonstrates using custom JavaScript for Amazon product extraction.
¥Crypto Analysis
¥Demonstrates how to crawl and analyze cryptocurrency data.
¥SERP API
¥Demonstrates using Crawl4AI with search engine result pages.
| 例子 | 描述 | 关联 |
|---|---|---|
| 亚马逊产品提取 | 演示如何使用 CSS 选择器从亚马逊搜索结果中提取结构化产品数据。 | 查看代码 |
| 带钩子的亚马逊 | 展示如何将钩子与亚马逊产品提取结合使用。 | 查看代码 |
| 使用 JavaScript 的亚马逊 | 演示使用自定义 JavaScript 进行亚马逊产品提取。 | 查看代码 |
| 密码分析 | 演示如何抓取和分析加密货币数据。 | 查看代码 |
| SERP API | 演示如何使用 Crawl4AI 和搜索引擎结果页面。 | 查看代码 |
反机器人和隐身功能
¥Anti-Bot & Stealth Features
¥Example
¥Description
¥Link
¥Stealth Mode Quick Start
¥Five practical examples showing how to use stealth mode for bypassing basic bot detection.
¥Stealth Mode Comprehensive
¥Comprehensive demonstration of stealth mode features with bot detection testing and comparisons.
¥Undetected Browser
¥Simple example showing how to use the undetected browser adapter.
¥Undetected Browser Demo
¥Basic demo comparing regular and undetected browser modes.
¥Undetected Tests
¥Advanced tests comparing regular vs undetected browsers on various bot detection services.
| 例子 | 描述 | 关联 |
|---|---|---|
| 隐身模式快速入门 | 五个实际示例展示如何使用隐身模式绕过基本的机器人检测。 | 查看代码 |
| 隐身模式综合 | 通过机器人检测测试和比较全面演示隐身模式功能。 | 查看代码 |
| 未检测到的浏览器 | 简单示例展示如何使用未检测到的浏览器适配器。 | 查看代码 |
| 未被检测到的浏览器演示 | 比较常规和未检测到的浏览器模式的基本演示。 | 查看代码 |
| 未检测到的测试 | 在各种机器人检测服务上对常规浏览器和未被检测到的浏览器进行高级测试。 | 查看文件夹 |
定制和安全
¥Customization & Security
¥Example
¥Description
¥Link
¥Hooks
¥Illustrates how to use hooks at different stages of the crawling process for advanced customization.
¥Identity-Based Browsing
¥Illustrates identity-based browsing configurations for authentic browsing experiences.
¥Proxy Rotation
¥Shows how to use proxy rotation for web scraping and avoiding IP blocks.
¥SSL Certificate
¥Illustrates SSL certificate handling and verification.
¥Language Support
¥Shows how to handle different languages during crawling.
¥Geolocation
¥Demonstrates how to use geolocation features.
| 例子 | 描述 | 关联 |
|---|---|---|
| 钩子 | 说明如何在爬取过程的不同阶段使用钩子进行高级定制。 | 查看代码 |
| 基于身份的浏览 | 说明基于身份的浏览配置以获得真实的浏览体验。 | 查看代码 |
| 代理轮换 | 展示如何使用代理轮换进行网页抓取并避免 IP 阻止。 | 查看代码 |
| SSL 证书 | 说明 SSL 证书处理和验证。 | 查看代码 |
| 语言支持 | 展示如何在爬取过程中处理不同的语言。 | 查看代码 |
| 地理位置 | 演示如何使用地理定位功能。 | 查看代码 |
Docker 与部署
¥Docker & Deployment
¥Example
¥Description
¥Link
¥Docker Config
¥Demonstrates how to create and use Docker configuration objects.
¥Docker Basic
¥A test suite for Docker deployment, showcasing various functionalities through the Docker API.
¥Docker REST API
¥Shows how to interact with Crawl4AI Docker using REST API calls.
¥Docker SDK
¥Demonstrates using the Python SDK for Crawl4AI Docker.
| 例子 | 描述 | 关联 |
|---|---|---|
| Docker 配置 | 演示如何创建和使用 Docker 配置对象。 | 查看代码 |
| Docker 基础 | Docker 部署的测试套件,通过 Docker API 展示各种功能。 | 查看代码 |
| Docker REST API | 展示如何使用 REST API 调用与 Crawl4AI Docker 进行交互。 | 查看代码 |
| Docker SDK | 演示如何使用 Crawl4AI Docker 的 Python SDK。 | 查看代码 |
应用示例
¥Application Examples
¥Example
¥Description
¥Link
¥Research Assistant
¥Demonstrates how to build a research assistant using Crawl4AI.
¥REST Call
¥Shows how to make REST API calls with Crawl4AI.
¥Chainlit Integration
¥Shows how to integrate Crawl4AI with Chainlit.
¥Crawl4AI vs FireCrawl
¥Compares Crawl4AI with the FireCrawl library.
| 例子 | 描述 | 关联 |
|---|---|---|
| 研究助理 | 演示如何使用 Crawl4AI 构建研究助手。 | 查看代码 |
| REST 调用 | 展示如何使用 Crawl4AI 进行 REST API 调用。 | 查看代码 |
| Chainlit 集成 | 展示如何将 Crawl4AI 与 Chainlit 集成。 | 查看指南 |
| Crawl4AI 与 FireCrawl | 将 Crawl4AI 与 FireCrawl 库进行比较。 | 查看代码 |
内容生成和 Markdown
¥Content Generation & Markdown
¥Example
¥Description
¥Link
¥Content Source
¥Demonstrates how to work with different content sources in markdown generation.
¥Content Source (Short)
¥A simplified version of content source usage.
¥Built-in Browser Guide
¥Guide for using the built-in browser capabilities.
| 例子 | 描述 | 关联 |
|---|---|---|
| 内容来源 | 演示如何在 markdown 生成中使用不同的内容源。 | 查看代码 |
| 内容来源(简短) | 内容源使用的简化版本。 | 查看代码 |
| 内置浏览器指南 | 使用内置浏览器功能的指南。 | 查看指南 |
运行示例
¥Running the Examples
要运行这些示例中的任何一个,您需要安装 Crawl4AI:
¥To run any of these examples, you'll need to have Crawl4AI installed:
然后,您可以运行如下示例脚本:
¥Then, you can run an example script like this:
有关需要额外依赖项或环境变量的示例,请参阅每个文件顶部的注释。
¥For examples that require additional dependencies or environment variables, refer to the comments at the top of each file.
一些示例可能需要: - API 密钥(用于基于 LLM 的示例) - Docker 设置(用于与 Docker 相关的示例) - 附加依赖项(在示例文件中指定)
¥Some examples may require: - API keys (for LLM-based examples) - Docker setup (for Docker-related examples) - Additional dependencies (specified in the example files)
贡献新示例
¥Contributing New Examples
如果您创建了一个有趣的示例,展示了 Crawl4AI 的独特用例或功能,我们鼓励您将其贡献到我们的示例库中。请参阅我们的贡献指南了解更多信息。
¥If you've created an interesting example that demonstrates a unique use case or feature of Crawl4AI, we encourage you to contribute it to our examples collection. Please see our contribution guidelines for more information.