Skip to main content

MrScraper Python SDK

An async Python client for MrScraper content fetching and Google SERP. Requires Python 3.9+.

Install and authenticate

python -m pip install -e .
export MRSCRAPER_API_TOKEN="YOUR_TOKEN"

These commands install the current checkout. To install version 0.5.0 from PyPI, run python -m pip install --upgrade mrscraper-sdk==0.5.0. The client reads MRSCRAPER_API_TOKEN automatically. You can also pass token="YOUR_TOKEN" to MrScraper. Pass http_client= if you want to reuse your own httpx.AsyncClient; otherwise the SDK creates one per request. Both methods are async and must be awaited.

Migrating to 0.5.0

Version 0.5.0 renames two public methods. Update existing calls as follows:

Previous method New method
client.fetch_content(...) client.scraper_api(...)
client.google_serp(...) client.web_search(...)

The previous method names have been removed. Arguments and response formats are unchanged from 0.4.0.

Scraper API

import asyncio
from mrscraper import MrScraper

async def main():
    client = MrScraper()
    result = await client.scraper_api("https://example.com")
    print(result["data"])

asyncio.run(main())

scraper_api sends a POST request to https://api.mrscraper.com. The JSON body contains the target URL, maxRetries, and optional tokenCap. Page options and the token are query parameters. The return value has status_code, data, and headers keys. The SDK parses JSON responses into Python values and returns other responses as text. Depending on the requested options, data may contain HTML, Markdown, a screenshot, or a combination; inspect the returned value before assuming it is an HTML string.

To request HTML, Markdown, and a screenshot together:

import asyncio
from mrscraper import MrScraper

async def main():
    client = MrScraper()
    result = await client.scraper_api(
        "https://example.com",
        html=True,
        markdown=True,
        screenshot=True,
        super=True,
    )
    print(result["data"])

asyncio.run(main())

Setting screenshot=True also enables browser rendering, even if browser_rendering=False is passed.

Option Default Description
url required Target URL
html, markdown True, False Request HTML, Markdown, or both
timeout 120 Page timeout in seconds, from 1 to 300
geo_code, proxy_country "US", None Geolocation country code and optional proxyCountry field
browser_rendering None True to force browser rendering, False to disable it, or None for automatic fallback
screenshot False Capture a screenshot; also forces browser rendering
super False Enable real device routing
use_proxy, proxy True, None Allow a proxy or supply username:password@host:port
home_page False Visit the site's root first; sent as warmStart=true
wait_for_selector None Wait for a CSS selector
block_resources, bypass_proxy False, False Block images, CSS, and fonts, or enable the API's proxy bypass behavior
cookie_jar, headers None, None Cookie configuration string and target request headers (dictionary or JSON string)
max_retries, token_cap 3, None Retry controls
stream None Request a streamed response, buffered by the SDK
discard_token_secret "" Value for the x-discard-token-secret header
import asyncio
from mrscraper import MrScraper

async def main():
    client = MrScraper()
    result = await client.web_search(
        "python web scraping",
        raw=False,
        region="us",
        language="en",
        page=1,
        format="json",
    )
    print(result["data"])

asyncio.run(main())

web_search sends a POST request to https://sync.scraper.mrscraper.com/api/google/serp/v2/sync. The first argument accepts query text or a full Google search URL; for a URL, the client extracts q, gl, hl, and start. Explicit options override values from the URL. The return value has status_code, data, and headers keys. raw=True is the default and requests HTML; set raw=False to use format.

Option Default Description
url required Search query or Google search URL
raw True Request HTML when true, regardless of format
format "json" "json" or "html" when raw=False
region, language None, None Country and language
page None One based results page
render_js False Render JavaScript features
timeout 600.0 Request timeout in seconds

Smoke test this checkout

file.py runs one live request per invocation. Set your token first, then run:

python file.py fetch-content --url "https://example.com" --super
python file.py google-serp --query "site:example.com" --format json

The fetch-content command calls scraper_api() and enables screenshot=true and warmStart=true by default. Pass --super to enable real device routing; the printed request URL should contain super=true. The google-serp command calls web_search() and requests JSON by default.

Use python file.py --help for the available options. Add --save-dir manual_results to save a full JSON response.

Publishing a release

Publishing is manual. Choose a version that has not been published to PyPI and set it in both pyproject.toml and src/mrscraper/__init__.py. This checkout is prepared for 0.5.0. From the repository root, run:

python -m pip install build twine pytest pytest-asyncio
python -m pip install -e .
python -m pytest -m "not integration" -q
python -m build --outdir dist/manual-0.5.0
ls dist/manual-0.5.0
python -m twine check dist/manual-0.5.0/mrscraper_sdk-0.5.0*
python -m twine upload --username __token__ dist/manual-0.5.0/mrscraper_sdk-0.5.0*

Before uploading, confirm that ls shows only the intended 0.5.0 files. Twine prompts for a PyPI API token as the password. Do not upload older files from dist/.

Errors

MrScraperError is the base exception. AuthenticationError indicates a missing or invalid token, APIError carries an HTTP status_code, and NetworkError indicates a connection or timeout failure.

Scraping login-protected pages can carry legal and compliance risks. Check the target site's terms and applicable law before automating access.

License

MIT © MrScraper

Metadata

Release files for mrscraper-sdk 0.5.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 mrscraper-sdk 0.5.0
File Size Uploaded
mrscraper_sdk-0.5.0.tar.gz 11.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mrscraper-sdk 0.5.0
File Interpreter ABI Platform
mrscraper_sdk-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / mrscraper_sdk-0.5.0.tar.gz

Download URL mrscraper_sdk-0.5.0.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d7f89b66a041d453587b33652bab88e50f8eda0d1270b6f62c1d8bbeecc04cae
BLAKE2b-256 checksum
How to use checksums
062ba219ac4a228392254661155e4c2355309723b8e7bacde02dfe660a4d7058
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release files / mrscraper_sdk-0.5.0-py3-none-any.whl

Download URL mrscraper_sdk-0.5.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73a09c62c2b9dec4635efcc6cc4a8813f6bf041141239f26698e0d90045848b6
BLAKE2b-256 checksum
How to use checksums
77ce98093175858d64ba42c01367f27bad8baa0df1f71b2a021f663f8a29d565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release history Release notifications | RSS feed

0.6.0

2 release files

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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