langchain-mrscraper
LangChain tools for the MrScraper Python SDK. The toolkit exposes the three public services of mrscraper-sdk>=0.9.0,<0.10.0: the Scraper API, Web Search, and account usage.
Installation
pip install -U langchain-mrscraper
The Python SDK and LangChain Core are installed automatically.
Quick start
import os
from langchain_mrscraper import MrScraperScraperAPI, MrScraperToolkit
os.environ["MRSCRAPER_API_KEY"] = "your-token"
tools = MrScraperToolkit().get_tools() # all three tools for an agent
result = MrScraperScraperAPI().invoke({
"url": "https://books.toscrape.com/",
"markdown": True,
})
print(result)
Every tool supports .invoke(...) and await .ainvoke(...). Authentication can be supplied through token, mrscraper_api_key, MRSCRAPER_API_KEY, or MRSCRAPER_API_TOKEN (in that order). You can also inject an existing mrscraper.MrScraper client using client=....
Available tools
| Class | Tool name | SDK method | Input fields |
|---|---|---|---|
MrScraperScraperAPI |
mrscraper_scraper_api |
scraper_api |
url, html, markdown, screenshot, plus page controls (below) |
MrScraperWebSearch |
mrscraper_web_search |
web_search |
query, country, num_results (10–100), timeout |
MrScraperAccount |
mrscraper_account |
account |
timeout |
Tool results are JSON strings containing the SDK's status_code, data, and headers.
Scraper API
Fetch a public web page as rendered HTML, Markdown, screenshot, or a combination.
import base64
import json
from langchain_mrscraper import MrScraperScraperAPI
tool = MrScraperScraperAPI()
html = json.loads(tool.invoke({"url": "https://books.toscrape.com/"}))
print(html["data"][:200]) # HTML only (the default) returns the HTML string
combined = json.loads(tool.invoke({
"url": "https://books.toscrape.com/",
"html": True,
"markdown": True,
"screenshot": True,
}))
print(combined["data"]["markdown"][:200])
png = base64.b64decode(combined["data"]["screenshot"])
html defaults to True; markdown and screenshot default to False. At least one must be true. Requesting Markdown or a screenshot returns an object in data with an entry for each requested output; the screenshot is a base64 string. screenshot=True enables browser rendering, so combining it with browser_rendering=False is rejected.
Page controls: timeout (1–300 seconds, default 120), geo_code (default "US"), proxy_country, block_resources, browser_rendering, super, use_proxy, proxy, wait_for_selector, wait_until, home_page, bypass_proxy, cookie_jar, headers, max_retries, token_cap, stream, and discard_token_secret. Invalid URLs, limits, or unsupported fields are rejected by the tool schema before a request is made.
Web Search
Search the web for real-time results: website URLs, titles, and descriptions.
from langchain_mrscraper import MrScraperWebSearch
result = MrScraperWebSearch().invoke({
"query": "e-menessaptieka.lv linkedin",
"country": "us",
"num_results": 10,
})
query is required. country is optional (the service default applies when omitted). num_results is an integer from 10 to 100 (default 10). timeout defaults to 600 seconds. The response data is {"success", "message", "data": [...]}, where each result has rank, title, url, description, and source.
Account
from langchain_mrscraper import MrScraperAccount
print(MrScraperAccount().invoke({}))
Returns subscription status, token usage and limits, remaining quota, and rate limits. timeout defaults to 30 seconds.
Select tools for an agent
from langchain_mrscraper import MrScraperToolkit
tools = MrScraperToolkit(
token="your-token",
tool_names=["mrscraper_scraper_api", "mrscraper_web_search"],
).get_tools()
load_mrscraper_tools(...) accepts the same configuration. tool_names filters by the exact names above; an empty list returns no tools.
Migration from 0.3.x
Version 0.5.0 requires mrscraper-sdk>=0.9.0,<0.10.0, which exposes exactly three public methods. The toolkit now returns three tools instead of ten.
| 0.3.x tool | 0.5.0 replacement |
|---|---|
MrScraperHTML (mrscraper_scraper_html) |
MrScraperScraperAPI with {"url": ...} |
MrScraperMarkdown (mrscraper_scraper_markdown) |
MrScraperScraperAPI with {"url": ..., "html": False, "markdown": True} |
MrScraperScreenshot (mrscraper_get_screenshot) |
MrScraperScraperAPI with {"url": ..., "html": False, "screenshot": True} |
MrScraperJSON, MrScraperMultiplePage, MrScraperSitemap, MrScraperBrand, MrScraperGetBrand |
Removed (no public SDK method). Fetch pages with MrScraperScraperAPI and let your model extract data, or pin langchain-mrscraper<0.4. |
MrScraperWebSearch (url, raw, format, region, language, page, render_js) |
MrScraperWebSearch (query, country, num_results, timeout) |
MrScraperAccount |
Unchanged |
MrScraperFetchHTML import alias |
Removed; use MrScraperScraperAPI |
Other notes:
- Screenshots now come back as a base64 string inside
data(data["screenshot"]) together with any other requested outputs. The 0.3.x screenshotfull_pageoption and itstimeout=300/wait_until="domcontentloaded"defaults no longer exist; passtimeoutandwait_untilexplicitly when needed. - Update toolkit
tool_namesfilters tomrscraper_scraper_api,mrscraper_web_search, andmrscraper_account. - Earlier tools (create/rerun/bulk-rerun scrapers and result listing) remain removed.
Testing
pip install -e '.[dev]'
pytest tests/unit_tests -v
pytest -m 'not integration'
Live smoke tests are opt-in and consume API quota:
MRSCRAPER_RUN_LIVE=1 MRSCRAPER_API_KEY=your-token pytest tests/integration_tests -m integration -v
python manual_check_tools.py runs every tool against the real API and saves responses to debug_results/.
Local release workflow
- Update
versioninpyproject.tomlwhen ready to release. - Build:
python -m build. - Validate:
python -m twine check dist/*. - Upload to TestPyPI:
python -m twine upload --repository testpypi dist/*. - Verify installation, then upload to PyPI:
python -m twine upload dist/*.
Provider and per-tool documentation for a LangChain docs submission live in docs/providers/mrscraper.mdx and docs/tools/*.mdx.
Metadata
Release files for langchain-mrscraper 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_mrscraper-0.5.0.tar.gz | 8.3 kB | Without provenance | Details for langchain_mrscraper-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_mrscraper-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_mrscraper-0.5.0-py3-none-any.whl |
Total release size: 17.1 kB
Release files / langchain_mrscraper-0.5.0.tar.gz
| Download URL | langchain_mrscraper-0.5.0.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5deb0efcc78fb4fd1ec42e445f65c0c418ac39150cf94e7305c710d3d51d4d2
|
|
BLAKE2b-256 checksum How to use checksums |
b36e9fe018bc6b3fa5d78734ec932495f494feff7ea7cfbd394c9abba1935251
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Release files / langchain_mrscraper-0.5.0-py3-none-any.whl
| Download URL | langchain_mrscraper-0.5.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
725fdbe631500aeb2efbbe79692701272a437f0aee040d8bb0d81fc5d1e77952
|
|
BLAKE2b-256 checksum How to use checksums |
39145037a2d7553448975c55f499a9bee6b6267d3aaebac3370667dc6312dc1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Security for langchain-mrscraper 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.