Metadata-Version: 2.5
Name: langchain-scrapeit
Version: 0.1.0
Summary: LangChain integration for ScrapeIt: load web pages and whole sites as Documents, scrape and search Google from agents.
Project-URL: Homepage, https://www.scrapeit.io/
Project-URL: Documentation, https://docs.scrapeit.io/products/ai-frameworks#langchain
License-Expression: MIT
Keywords: ai-agents,document-loader,google-search,langchain,llm,scrapeit,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
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.11
Requires-Dist: langchain-core<2.0.0,>=1.0.0
Requires-Dist: scrapeit-sdk<0.5,>=0.4.0
Provides-Extra: dev
Requires-Dist: langchain-tests==1.1.9; extra == 'dev'
Requires-Dist: pytest-asyncio==1.5.0; extra == 'dev'
Requires-Dist: pytest==9.2.0; extra == 'dev'
Description-Content-Type: text/markdown

# langchain-scrapeit

[ScrapeIt](https://www.scrapeit.io/) for [LangChain](https://docs.langchain.com/): load web pages and whole
sites as `Document`s, and give agents tools to scrape a page and search Google. ScrapeIt fetches each page
through its proxies, renders JavaScript when the page needs it and gets past anti-bot protection.

| Class                      | What it does                                                                                 |
| -------------------------- | -------------------------------------------------------------------------------------------- |
| `ScrapeitLoader`           | Document loader: URLs to `Document`s (markdown, text or HTML); `mode="crawl"` crawls a site. |
| `ScrapeitScrapeTool`       | Agent tool `scrapeit_scrape`: one URL in, the page as markdown out.                          |
| `ScrapeitGoogleSearchTool` | Agent tool `scrapeit_google_search`: a query in, the parsed Google results page out (JSON).  |

## Install

```bash
pip install -U langchain-scrapeit
```

Python 3.11+, `langchain-core` 1.x. 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 any class. The key is sent only in the `x-api-key` header to
`https://api.scrapeit.io`; it is never part of a tool's `repr`, its serialized form or an error message.

## Load pages

```python
from langchain_scrapeit import ScrapeitLoader

loader = ScrapeitLoader(urls=["https://example.com"])
docs = loader.load()

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

`params` passes any [Web Scraping API parameter](https://docs.scrapeit.io/products/web-scraping-api):

```python
loader = ScrapeitLoader(
    urls=["https://example.com/pricing"],
    output_format="text",  # "markdown" (default), "text" or "html"
    params={"jsRendering": True, "proxyType": "residential", "proxyCountry": "us"},
)
```

`lazy_load()`, `aload()` and `alazy_load()` work too; the async methods use `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
loader = ScrapeitLoader(
    urls="https://example.com/blog/",
    mode="crawl",
    params={"maxDepth": 2, "limit": 50, "includePaths": ["/blog/*"]},
)
docs = loader.load()  # metadata: source, depth, status_code, credits, crawl_job_id
```

## Agent tools

```python
from langchain_scrapeit import ScrapeitGoogleSearchTool, ScrapeitScrapeTool

scrape = ScrapeitScrapeTool()
search = ScrapeitGoogleSearchTool()

scrape.invoke({"url": "https://example.com"})  # the page as markdown
results = search.invoke({"query": "best coffee maker", "country": "us", "language": "en"})
results["organic_results"][0]["link"]
```

Give them to any tool-calling agent (`pip install langchain` plus the integration of your chat model):

```python
from langchain.agents import create_agent

agent = create_agent("openai:gpt-4.1-mini", tools=[scrape, search])
agent.invoke({"messages": [{"role": "user", "content": "What does example.com say about itself?"}]})
```

`ScrapeitScrapeTool(params={...})` sets Web Scraping API parameters for every call, and
`output_format="text"` returns plain text instead of markdown.

## Errors

A failed request raises `scrapeit.ScrapeitError` from the loader and `ToolException` from a tool. Both carry
the stable API error code, for example `INSUFFICIENT_CREDITS`, `TARGET_BLOCKED` or `SCRAPE_TIMEOUT`, and the
correlation id to quote to support. Build a tool with `handle_tool_error=True` to hand the error text to the
agent instead of raising. A missing key fails when a tool 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 loader leaves out a page whose answer
was empty.

## Credits

Every scrape, search 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)
- [Google SERP API](https://docs.scrapeit.io/products/google-serp-api)
- [Error codes](https://docs.scrapeit.io/guide/errors)
