LLM-powered web scraping in Python
Project description
LLM Scraper Python
A Python port of the LLM-powered web scraping library, using html2text for HTML processing.
Installation
- Create a virtual environment and install dependencies:
uv sync - 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
llmscraper-0.1.0.tar.gz
(7.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llmscraper-0.1.0.tar.gz.
File metadata
- Download URL: llmscraper-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b9d0ad126d0a1d389078fecf64156dc55d2a2b0632a1054b8e87db0be43d21f
|
|
| MD5 |
437f64526f0b03ef4e73e8b8c4ec7002
|
|
| BLAKE2b-256 |
bac9493430652d13625fad842793dd1a796f7e265afc76cbd5f84b773fcb1667
|
File details
Details for the file llmscraper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llmscraper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1015a7adacb7230e8c6b9306513ab211392b5ed9f75d92330124a34a9437fec
|
|
| MD5 |
8825618ef0b014a65478f554946d2163
|
|
| BLAKE2b-256 |
0340030e398e987db07723a8d0babb66901528730584e028706c04cb1599af75
|