Metadata-Version: 2.5
Name: llama-index-readers-scrapeit
Version: 0.1.0
Summary: llama-index readers scrapeit integration: web pages and whole sites as Documents through the ScrapeIt Web Scraping API.
Project-URL: Homepage, https://www.scrapeit.io/
Project-URL: Documentation, https://docs.scrapeit.io/products/ai-frameworks#llamaindex
Author: ScrapeIt
License-Expression: MIT
Keywords: crawler,llama-index,markdown,reader,scrapeit,web,web scraping
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: <4.0,>=3.11
Requires-Dist: llama-index-core<0.15,>=0.14.0
Requires-Dist: scrapeit-sdk<0.5,>=0.4.0
Provides-Extra: dev
Requires-Dist: pytest-asyncio==1.5.0; extra == 'dev'
Requires-Dist: pytest==9.2.0; extra == 'dev'
Description-Content-Type: text/markdown

# LlamaIndex Readers Integration: ScrapeIt

`ScrapeitWebReader` loads web pages and whole sites into LlamaIndex `Document`s with
[ScrapeIt](https://www.scrapeit.io/), a web scraping API: each page is fetched through ScrapeIt's proxies,
rendered in a browser when it needs JavaScript and got past anti-bot protection, then returned as
markdown, text or HTML.

## Install

```bash
pip install llama-index-readers-scrapeit
```

Python 3.11+, `llama-index-core` 0.14. Built on the official [`scrapeit-sdk`](https://pypi.org/project/scrapeit-sdk/).

## Authentication

Create an API key in the ScrapeIt dashboard under **Workspace → API Keys** (scope `scrape:web`; add
`scrapers:run` and `scrapers:read` for crawl mode) and set it in the environment:

```bash
export SCRAPEIT_API_KEY="YOUR_SCRAPEIT_API_KEY"
```

Or pass `api_key="..."` to the reader. The key is sent only in the `x-api-key` header to
`https://api.scrapeit.io` and is never part of the serialized reader (`to_dict()`, `to_json()`).

## Usage

```python
from llama_index.readers.scrapeit import ScrapeitWebReader

reader = ScrapeitWebReader()
documents = reader.load_data(urls=["https://example.com"])

print(documents[0].text)      # "Example Domain ..."
print(documents[0].metadata)  # {"url": "https://example.com", "request_id": "...", "status_code": 200, "credits": 4}
```

Build an index from the pages:

```python
from llama_index.core import VectorStoreIndex

index = VectorStoreIndex.from_documents(documents)
answer = index.as_query_engine().query("What is this domain for?")
```

`params` passes any [Web Scraping API parameter](https://docs.scrapeit.io/products/web-scraping-api), and
`output_format` picks the document text (`"markdown"`, the default, `"text"` or `"html"`):

```python
reader = ScrapeitWebReader(
    output_format="text",
    params={"jsRendering": True, "proxyType": "residential", "proxyCountry": "us"},
)
```

`await reader.aload_data(urls=[...])` does the same on `scrapeit.AsyncScrapeit`.

### Crawl a site

`mode="crawl"` starts one [Website Crawler](https://docs.scrapeit.io/products/website-crawler) job from the
URLs, waits for it to finish (`crawl_timeout`, 600 seconds by default) and returns a document per crawled
page (pages that failed, were skipped or were blocked are left out). `params` takes the crawler options:

```python
reader = ScrapeitWebReader(
    mode="crawl",
    params={"maxDepth": 2, "limit": 50, "includePaths": ["/blog/*"]},
)
documents = reader.load_data(urls=["https://example.com/blog/"])  # metadata: url, depth, status_code, credits, crawl_job_id
```

## Errors

A failed request raises `scrapeit.ScrapeitError`. Branch on its stable `code` (for example
`INSUFFICIENT_CREDITS`, `TARGET_BLOCKED` or `SCRAPE_TIMEOUT`) and quote its `correlation_id` to support. A
missing key fails when the reader is created (`MISSING_API_KEY`).

A page is never replaced by an empty or a challenge text: a scrape that failed raises `SCRAPE_FAILED`
(nothing charged, the reason in `details["non_billable_failure_category"]`), a site that answered with its
anti-bot page raises `TARGET_BLOCKED` (charged: retry with `jsRendering` or residential proxies), and a crawl
that ended `failed` raises `CRAWL_FAILED` with `details["job_id"]`. The reader leaves out a page whose answer
was empty.

## Credits

Every scraped and crawled page spends credits from your ScrapeIt plan, the same as a direct API call;
failures on ScrapeIt's side are free. See [billing and credits](https://docs.scrapeit.io/guide/billing-and-credits).

## Links

- [Docs: AI frameworks](https://docs.scrapeit.io/products/ai-frameworks)
- [Web Scraping API reference](https://docs.scrapeit.io/products/web-scraping-api)
- [Error codes](https://docs.scrapeit.io/guide/errors)
