Skip to main content

LLM Scraper Python

A Python port of the LLM-powered web scraping library, using html2text for HTML processing.

Installation

  1. Create a virtual environment and install dependencies:
    uv sync
    
  2. Install Playwright browser binaries:
    uv run playwright install
    

Usage

import asyncio
from typing import List
from playwright.async_api import async_playwright
from pydantic import BaseModel
from openai import AsyncOpenAI
from llmscraper import LLMScraper

class Story(BaseModel):
    title: str
    url: str
    points: int
    by: str
    comments: int

class HackerNews(BaseModel):
    stories: List[Story]

async def main():
    client = AsyncOpenAI()
    scraper = LLMScraper(client)

    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        await page.goto("https://news.ycombinator.com")

        result = await scraper.run(
            page,
            schema=HackerNews,
            options={"limit": 5},
        )
        print(result)

        await browser.close()

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

Examples

See the examples/ directory for more usage examples.

Metadata

Release files for llmscraper 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llmscraper 0.1.0
File Size Uploaded
llmscraper-0.1.0.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llmscraper 0.1.0
File Interpreter ABI Platform
llmscraper-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / llmscraper-0.1.0.tar.gz

Download URL llmscraper-0.1.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7b9d0ad126d0a1d389078fecf64156dc55d2a2b0632a1054b8e87db0be43d21f
BLAKE2b-256 checksum
How to use checksums
bac9493430652d13625fad842793dd1a796f7e265afc76cbd5f84b773fcb1667
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / llmscraper-0.1.0-py3-none-any.whl

Download URL llmscraper-0.1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1015a7adacb7230e8c6b9306513ab211392b5ed9f75d92330124a34a9437fec
BLAKE2b-256 checksum
How to use checksums
0340030e398e987db07723a8d0babb66901528730584e028706c04cb1599af75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page