Skip to main content

A smart web scraper with LLM-powered extraction capabilities

Project description

Web Scraper with LLM Extraction

A powerful and lightweight web scraping library with LLM extraction capabilities. This library combines web scraping with AI-powered content extraction using either OpenAI or OpenRouter APIs.

Features

  • Configurable web scraping with Playwright
  • Support for both headless and visible browser modes
  • Content cleaning and preprocessing
  • LLM-based information extraction
  • Support for both OpenAI and OpenRouter APIs
  • Customizable schema definitions with type specifications:
    • String fields
    • Array fields
    • Object fields with nested properties
  • Ad blocking and media handling
  • Automatic handling of srcset attributes
  • HTML minification support

Installation

pip install aiohttp beautifulsoup4 fake-useragent playwright pydantic tiktoken openai lxml
pip install scrapeneatly

Quick Start

import asyncio
from scrapeneatly import scrape_product

async def main():
    # Define what you want to extract
    fields = {
        "title": {
            "description": "Product title",
            "type": "string"
        },
        "images": {
            "description": "Product images",
            "type": "array",
            "items": {"type": "string"}
        }
    }

    result = await scrape_product(
        url="https://example.com/product",
        fields_to_extract=fields,
        provider="openai",  # or "openrouter"
        api_key="your-api-key",
        model="anthropic/claude-2"  # optional, for OpenRouter
    )

    if result["success"]:
        print(result["data"])

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

Advanced Usage

Specifying Field Types

fields = {
    "price": {
        "description": "Product price",
        "type": "string"
    },
    "variants": {
        "description": "Product variants",
        "type": "array",
        "items": {
            "type": "object",
            "properties": {
                "color": {"type": "string"},
                "size": {"type": "string"}
            }
        }
    }
}

Using OpenRouter with Custom Model

result = await scrape_product(
    url="your_url",
    fields_to_extract=fields,
    provider="openrouter",
    api_key="your-openrouter-key",
    model="google/gemini-2.0-flash-001"
)

Using OpenAI models - Uses gpt4o - please don't specify the model

result = await scrape_product(
    url="your_url",
    fields_to_extract=fields,
    provider="openai",
    api_key="your-openai-api-key",
)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapeneatly-0.1.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapeneatly-0.1.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file scrapeneatly-0.1.2.tar.gz.

File metadata

  • Download URL: scrapeneatly-0.1.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for scrapeneatly-0.1.2.tar.gz
Algorithm Hash digest
SHA256 04090b1fcbec22401ee4e076b215f8b847e43a21e133de48b90bedefdc94856a
MD5 73b0ec429ac566955f5fdb17757d4bbd
BLAKE2b-256 10357212711245d13568d7e8ca338209c3d85f3e250a2c42ee26395e287fa2e2

See more details on using hashes here.

File details

Details for the file scrapeneatly-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: scrapeneatly-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for scrapeneatly-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19971f496839fd764132ed1a1a7a54b0c47dc60cab6c7d326d6298da821ffe48
MD5 0c61876d86ea43b04a699556f0914a13
BLAKE2b-256 4d299fe38e775620995ef504fcda432e3a18960fc14fe365fd0811abad31ad8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page