█

AI/TLDR

Me pague um café
Me pague um café

Crawlee for Python

Biblioteca Python de web scraping e automação de navegador para criar crawlers confiáveis

Web Scraping & CrawlingCódigo aberto
Idioma
Python
EM RESUMO

What is Crawlee for Python?

Crawlee for Python é a versão em Python da biblioteca Crawlee, da Apify. It sits in the Web Scraping & Crawling category of the Data & Labeling tools and is open-source, written in Python. To get started: instalar o Crawlee.

Visão geral

Crawlee for Python é a versão em Python da biblioteca Crawlee, da Apify. Ela cuida do crawling e do scraping de ponta a ponta: seguir links, extrair dados e armazená-los em formatos legíveis por máquina, para que você possa focar nos dados que quer, e não na infraestrutura ao redor deles.

Ele é voltado para desenvolvedores Python que precisam coletar dados da web em escala, incluindo dados para IA, LLMs e pipelines de RAG. Oferece tanto um crawler baseado em HTTP, que analisa HTML com BeautifulSoup, quanto um crawler baseado em Playwright para sites que precisam de JavaScript do lado do cliente, com configurações padrão ajustadas para que os crawlers passem despercebidos e evitem as proteções comuns contra bots.

No universo de web scraping e crawling, o Crawlee é um framework completo, e não uma ferramenta de uso único. Ele gerencia para você a fila de requisições, o enfileiramento de links, as novas tentativas e o armazenamento persistente, e expõe configurações avançadas quando os padrões não bastam. Também há uma implementação em TypeScript para projetos JavaScript.

O que faz

  • Dois tipos de crawler: BeautifulSoupCrawler para scraping rápido de HTML via HTTP, e PlaywrightCrawler para sites pesados em JavaScript
  • A configuração padrão faz os crawlers parecerem humanos para reduzir bloqueios por proteções modernas contra bots
  • Enfileiramento de links integrado com context.enqueue_links() para rastrear um site seguindo os links encontrados
  • Armazenamento persistente via context.push_data(), que grava os dados extraídos em um diretório local storage/
  • CLI do Crawlee com modelos de projeto prontos para criar um novo crawler rapidamente
  • Instalação modular: um pacote central enxuto mais extras opcionais, como beautifulsoup e all, para manter as dependências no mínimo

Primeiros passos

O Crawlee é publicado no PyPI como o pacote crawlee. Instale o pacote, configure o Playwright e, em seguida, execute um crawler mínimo.

Instalar o Crawlee

Instale o pacote com todos os recursos e depois instale as dependências do navegador do Playwright.

bashbash
python -m pip install 'crawlee[all]'
playwright install

Verificar a instalação

Confirme que o Crawlee pode ser importado e exiba a versão.

bashbash
python -c 'import crawlee; print(crawlee.__version__)'

Criar um projeto com a CLI (opcional)

O começo mais rápido é a CLI do Crawlee, que oferece modelos prontos. Ela requer o uv.

bashbash
uvx 'crawlee[cli]' create my-crawler

Escrever um crawler mínimo

Este BeautifulSoupCrawler busca páginas via HTTP, extrai o título, armazena os dados e segue links. Cada execução cria um diretório storage/ no seu diretório de trabalho.

pythonpython
import asyncio

from crawlee.crawlers import BeautifulSoupCrawler, BeautifulSoupCrawlingContext

async def main() -> None:
    crawler = BeautifulSoupCrawler(
        # Limit the crawl to max requests. Remove or increase it for crawling all links.
        max_requests_per_crawl=10,
    )

    # Define the default request handler, which will be called for every request.
    @crawler.router.default_handler
    async def request_handler(context: BeautifulSoupCrawlingContext) -> None:
        context.log.info(f'Processing {context.request.url} ...')

        # Extract data from the page.
        data = {
            'url': context.request.url,
            'title': context.soup.title.string if context.soup.title else None,
        }

        # Push the extracted data to the default dataset.
        await context.push_data(data)

        # Enqueue all links found on the page.
        await context.enqueue_links()

    # Run the crawler with the initial list of URLs.
    await crawler.run(['https://crawlee.dev'])

if __name__ == '__main__':
    asyncio.run(main())

Commands and code are distilled from the project's own documentation — always check the repositório oficial para as novidades.

Quando usar

  • Coletar dados da web para alimentar pipelines de IA, LLM e RAG
  • Extrair dados estruturados de páginas HTML estáticas em escala, usando o BeautifulSoupCrawler baseado em HTTP
  • Rastrear sites pesados em JavaScript que precisam de um navegador real, via PlaywrightCrawler
  • Criar um crawler de site que segue links e salva os resultados em armazenamento local para processamento posterior

How Crawlee for Python compares

Crawlee for Python alongside other open-source web scraping & crawling tools AI/TLDR tracks, ranked by GitHub stars.

FerramentaEstrelasO que faz
Firecrawl★ 214kA crawling service and API that converts whole websites into clean Markdown or structured JSON ready for LLMs.
Agent Reach★ 116kA capability layer that installs, health-checks and routes readers so a CLI agent can read and search web pages, YouTube, RSS, GitHub, Reddit, Twitter/X and more without API fees.
Scrapling★ 107kA Python web scraping framework whose parser relocates your elements when pages change, with stealthy fetchers and a Scrapy-like spider engine for full crawls.
Crawl4AI★ 88.2kA local-first Python web crawler that turns pages into clean Markdown for use in RAG and LLM pipelines.
Scrapy★ 65.7kA mature Python framework for writing fast spiders that crawl websites and extract structured data at scale.
changedetection.io★ 36.1kA self-hosted web page change monitor with XPath/CSS/jq filters, browser steps and restock alerts, which can route every diff through an LLM to suppress noise.
ScrapeGraphAI★ 33kA Python library that uses LLMs and a graph pipeline to extract data from pages based on natural-language prompts.
Crawlee for Python★ 9.7kBiblioteca Python de web scraping e automação de navegador para criar crawlers confiáveis