Skip to content

MCP Server API Reference

The Scrapling MCP Server provides eleven powerful tools for web scraping through the Model Context Protocol (MCP). This server integrates Scrapling's capabilities directly into AI chatbots and agents, allowing conversational web scraping with advanced anti-bot bypass features.

You can start the MCP server by running:

scrapling mcp

Or import the server class directly:

from scrapling.core.ai import ScraplingMCPServer

server = ScraplingMCPServer()
server.serve(http=False, host="127.0.0.1", port=8000)

To set a custom Chromium-compatible browser executable for browser-based MCP tools, pass executable_path:

server = ScraplingMCPServer(executable_path="/path/to/chromium")

Response Model

The standardized response structure that's returned by all MCP server tools:

scrapling.core.ai.ResponseModel

Bases: BaseModel


              flowchart TD
              scrapling.core.ai.ResponseModel[ResponseModel]

              

              click scrapling.core.ai.ResponseModel href "" "scrapling.core.ai.ResponseModel"
            

Request's response information structure.

status class-attribute instance-attribute

status = Field(
    description="The status code returned by the website."
)

content class-attribute instance-attribute

content = Field(
    description="The content as Markdown/HTML or the text content of the page."
)

url class-attribute instance-attribute

url = Field(
    description="The URL given by the user that resulted in this response."
)

Session Models

Model classes for session management:

scrapling.core.ai.SessionInfo

Bases: BaseModel


              flowchart TD
              scrapling.core.ai.SessionInfo[SessionInfo]

              

              click scrapling.core.ai.SessionInfo href "" "scrapling.core.ai.SessionInfo"
            

Information about an open browser session.

session_id class-attribute instance-attribute

session_id = Field(
    description="The unique identifier of the session."
)

session_type class-attribute instance-attribute

session_type = Field(
    description="The type of the session: 'dynamic', 'stealthy', or 'static'."
)

created_at class-attribute instance-attribute

created_at = Field(
    description="ISO timestamp of when the session was created."
)

is_alive class-attribute instance-attribute

is_alive = Field(
    description="Whether the session is still alive and usable."
)

settings class-attribute instance-attribute

settings = Field(
    default_factory=dict,
    description="The effective settings this session was created with.",
)

scrapling.core.ai.SessionCreatedModel

Bases: SessionInfo


              flowchart TD
              scrapling.core.ai.SessionCreatedModel[SessionCreatedModel]
              scrapling.core.ai.SessionInfo[SessionInfo]

                              scrapling.core.ai.SessionInfo --> scrapling.core.ai.SessionCreatedModel
                


              click scrapling.core.ai.SessionCreatedModel href "" "scrapling.core.ai.SessionCreatedModel"
              click scrapling.core.ai.SessionInfo href "" "scrapling.core.ai.SessionInfo"
            

Response returned when a new session is created.

message class-attribute instance-attribute

message = Field(description='A confirmation message.')

session_id class-attribute instance-attribute

session_id = Field(
    description="The unique identifier of the session."
)

session_type class-attribute instance-attribute

session_type = Field(
    description="The type of the session: 'dynamic', 'stealthy', or 'static'."
)

created_at class-attribute instance-attribute

created_at = Field(
    description="ISO timestamp of when the session was created."
)

is_alive class-attribute instance-attribute

is_alive = Field(
    description="Whether the session is still alive and usable."
)

settings class-attribute instance-attribute

settings = Field(
    default_factory=dict,
    description="The effective settings this session was created with.",
)

scrapling.core.ai.SessionClosedModel

Bases: BaseModel


              flowchart TD
              scrapling.core.ai.SessionClosedModel[SessionClosedModel]

              

              click scrapling.core.ai.SessionClosedModel href "" "scrapling.core.ai.SessionClosedModel"
            

Response returned when a session is closed.

session_id class-attribute instance-attribute

session_id = Field(
    description="The unique identifier of the closed session."
)

message class-attribute instance-attribute

message = Field(description='A confirmation message.')

MCP Server Class

The main MCP server class that provides all web scraping tools:

scrapling.core.ai.ScraplingMCPServer

ScraplingMCPServer(executable_path=None, auth_token=None)

Create a Scrapling MCP server.

PARAMETER DESCRIPTION
executable_path

Optional global Chromium-compatible browser executable path for browser tools. If omitted, the SCRAPLING_EXECUTABLE_PATH environment variable is used when set.

TYPE: Optional[str] DEFAULT: None

auth_token

Optional shared token that clients must send as Authorization: Bearer <token>. If omitted, the SCRAPLING_MCP_AUTH_TOKEN environment variable is used when set. It only applies to the streamable-http transport.

TYPE: Optional[str] DEFAULT: None

Source code in scrapling/core/ai.py
def __init__(self, executable_path: Optional[str] = None, auth_token: Optional[str] = None):
    """Create a Scrapling MCP server.

    :param executable_path: Optional global Chromium-compatible browser executable path for browser tools.
        If omitted, the SCRAPLING_EXECUTABLE_PATH environment variable is used when set.
    :param auth_token: Optional shared token that clients must send as `Authorization: Bearer <token>`.
        If omitted, the SCRAPLING_MCP_AUTH_TOKEN environment variable is used when set. It only applies
        to the streamable-http transport.
    """
    self._sessions: Dict[str, _SessionEntry] = {}
    self._executable_path = executable_path or environ.get(MCP_EXECUTABLE_PATH_ENV) or None
    self._auth_token = auth_token or environ.get(MCP_AUTH_TOKEN_ENV) or None

open_session async

open_session(
    session_type,
    session_id=None,
    headless=True,
    real_chrome=False,
    timezone_id=None,
    locale=None,
    useragent=None,
    proxy=None,
    cdp_url=None,
    executable_path=None,
    cookies=None,
    hide_canvas=False,
    block_webrtc=False,
    allow_webgl=True,
    additional_args=None,
)

Open a persistent browser session that can be reused across multiple session_fetch calls. This avoids the overhead of launching a new browser for each request. Sessions hold the browser-level configuration only; per-request options are passed to session_fetch on each call.

PARAMETER DESCRIPTION
session_type

The type of session to open. Use "dynamic" for standard Playwright browser, or "stealthy" for anti-bot bypass with fingerprint spoofing.

TYPE: BrowserSessionType

session_id

Optional custom session ID. If not provided, a random 12-character hex ID will be generated. Useful for naming sessions for easier management.

TYPE: Optional[str] DEFAULT: None

headless

Run the browser in headless/hidden (default), or headful/visible mode.

TYPE: bool DEFAULT: True

real_chrome

If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.

TYPE: bool DEFAULT: False

timezone_id

Changes the timezone of the browser. Defaults to the system timezone.

TYPE: str | None DEFAULT: None

locale

Specify user locale, for example, en-GB, de-DE, etc.

TYPE: str | None DEFAULT: None

useragent

Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.

TYPE: Optional[str] DEFAULT: None

proxy

The proxy used for every request in this session, as a string or a dictionary with the keys 'server', 'username', and 'password' only.

TYPE: Optional[str | Dict[str, str]] DEFAULT: None

cdp_url

Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.

TYPE: Optional[str] DEFAULT: None

executable_path

Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this session.

TYPE: Optional[str] DEFAULT: None

cookies

Set cookies for the session. It should be in a dictionary format that Playwright accepts.

TYPE: Sequence[SetCookieParam] | None DEFAULT: None

hide_canvas

(Stealthy only) Add random noise to canvas operations to prevent fingerprinting.

TYPE: bool DEFAULT: False

block_webrtc

(Stealthy only) Forces WebRTC to respect proxy settings to prevent local IP address leak.

TYPE: bool DEFAULT: False

allow_webgl

(Stealthy only) Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.

TYPE: bool DEFAULT: True

additional_args

(Stealthy only) Additional arguments to be passed to Playwright's context as additional settings.

TYPE: Optional[Dict] DEFAULT: None

Source code in scrapling/core/ai.py
async def open_session(
    self,
    session_type: BrowserSessionType,
    session_id: Optional[str] = None,
    headless: bool = True,
    real_chrome: bool = False,
    timezone_id: str | None = None,
    locale: str | None = None,
    useragent: Optional[str] = None,
    proxy: Optional[str | Dict[str, str]] = None,
    cdp_url: Optional[str] = None,
    executable_path: Optional[str] = None,
    cookies: Sequence[SetCookieParam] | None = None,
    # Stealthy-only params (ignored for dynamic sessions)
    hide_canvas: bool = False,
    block_webrtc: bool = False,
    allow_webgl: bool = True,
    additional_args: Optional[Dict] = None,
) -> SessionCreatedModel:
    """Open a persistent browser session that can be reused across multiple `session_fetch` calls.
    This avoids the overhead of launching a new browser for each request. Sessions hold the browser-level
    configuration only; per-request options are passed to `session_fetch` on each call.

    :param session_type: The type of session to open. Use "dynamic" for standard Playwright browser, or "stealthy" for anti-bot bypass with fingerprint spoofing.
    :param session_id: Optional custom session ID. If not provided, a random 12-character hex ID will be generated. Useful for naming sessions for easier management.
    :param headless: Run the browser in headless/hidden (default), or headful/visible mode.
    :param real_chrome: If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.
    :param timezone_id: Changes the timezone of the browser. Defaults to the system timezone.
    :param locale: Specify user locale, for example, `en-GB`, `de-DE`, etc.
    :param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
    :param proxy: The proxy used for every request in this session, as a string or a dictionary with the keys 'server', 'username', and 'password' only.
    :param cdp_url: Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.
    :param executable_path: Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this session.
    :param cookies: Set cookies for the session. It should be in a dictionary format that Playwright accepts.
    :param hide_canvas: (Stealthy only) Add random noise to canvas operations to prevent fingerprinting.
    :param block_webrtc: (Stealthy only) Forces WebRTC to respect proxy settings to prevent local IP address leak.
    :param allow_webgl: (Stealthy only) Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.
    :param additional_args: (Stealthy only) Additional arguments to be passed to Playwright's context as additional settings.
    """
    session_id = self._new_session_id(session_id)
    common_kwargs: Dict[str, Any] = dict(
        proxy=proxy,
        locale=locale,
        cookies=cookies,
        cdp_url=cdp_url,
        headless=headless,
        block_ads=True,
        useragent=useragent,
        timezone_id=timezone_id,
        real_chrome=real_chrome,
        executable_path=self._resolve_executable_path(executable_path),
    )

    session: Union[AsyncDynamicSession, AsyncStealthySession]
    if session_type == "stealthy":
        session = AsyncStealthySession(
            **common_kwargs,
            hide_canvas=hide_canvas,
            block_webrtc=block_webrtc,
            allow_webgl=allow_webgl,
            additional_args=additional_args,
        )
    else:
        session = AsyncDynamicSession(**common_kwargs)

    await session.start()
    return self._register_session(session_id, session, session_type)

open_request_session async

open_request_session(
    session_id=None, impersonate="chrome", proxy=None
)

Open a persistent HTTP requests session (no browser) that can be reused across multiple session_make_request calls, keeping cookies, connections, and the browser fingerprint between requests. The session holds this configuration only; per-request options are passed to session_make_request on each call. It shares close_session/list_sessions with the browser sessions and shows there as a 'static' session.

PARAMETER DESCRIPTION
session_id

Optional custom session ID. If not provided, a random 12-character hex ID will be generated. Useful for naming sessions for easier management.

TYPE: Optional[str] DEFAULT: None

impersonate

Browser version to impersonate its fingerprint on every request. It's using the latest chrome version by default.

TYPE: ImpersonateType DEFAULT: 'chrome'

proxy

The proxy URL used for every request in this session. Format: "http://username:password@localhost:8030".

TYPE: Optional[str] DEFAULT: None

Source code in scrapling/core/ai.py
async def open_request_session(
    self,
    session_id: Optional[str] = None,
    impersonate: ImpersonateType = "chrome",
    proxy: Optional[str] = None,
) -> SessionCreatedModel:
    """Open a persistent HTTP requests session (no browser) that can be reused across multiple
    `session_make_request` calls, keeping cookies, connections, and the browser fingerprint between requests.
    The session holds this configuration only; per-request options are passed to `session_make_request` on each call.
    It shares `close_session`/`list_sessions` with the browser sessions and shows there as a 'static' session.

    :param session_id: Optional custom session ID. If not provided, a random 12-character hex ID will be generated. Useful for naming sessions for easier management.
    :param impersonate: Browser version to impersonate its fingerprint on every request. It's using the latest chrome version by default.
    :param proxy: The proxy URL used for every request in this session. Format: "http://username:password@localhost:8030".
    """
    session_id = self._new_session_id(session_id)
    session = FetcherSession(impersonate=impersonate, proxy=proxy)
    await session.__aenter__()
    return self._register_session(session_id, session, "static")

close_session async

close_session(session_id)

Close a persistent session and free its resources.

PARAMETER DESCRIPTION
session_id

The unique identifier of the session to close. Use list_sessions to see active sessions.

TYPE: str

Source code in scrapling/core/ai.py
async def close_session(
    self,
    session_id: str,
) -> SessionClosedModel:
    """Close a persistent session and free its resources.

    :param session_id: The unique identifier of the session to close. Use list_sessions to see active sessions.
    """
    entry = self._sessions.pop(session_id, None)
    if entry is None:
        raise ValueError(f"Session '{session_id}' not found. Use list_sessions to see active sessions.")

    if entry.session_type == "static":
        await entry.session.__aexit__(None, None, None)
    else:
        await entry.session.close()
    return SessionClosedModel(
        session_id=session_id,
        message=f"Session '{session_id}' closed successfully.",
    )

list_sessions async

list_sessions()

List all active sessions with their details, including the effective settings each one was created with.

Source code in scrapling/core/ai.py
async def list_sessions(self) -> List[SessionInfo]:
    """List all active sessions with their details, including the effective settings each one was created with."""
    return [
        SessionInfo(
            session_id=sid,
            session_type=entry.session_type,
            created_at=entry.created_at,
            is_alive=entry.session._is_alive,
            settings=_session_settings(entry.session),
        )
        for sid, entry in self._sessions.items()
    ]

screenshot async

screenshot(
    url,
    session_id,
    image_type="png",
    full_page=False,
    quality=None,
    wait=0,
    wait_selector=None,
    wait_selector_state="attached",
    network_idle=False,
    timeout=30000,
)

Capture a screenshot of a web page using an existing browser session and return it as an image. A browser session must be opened first with open_session (either dynamic or stealthy); the session ID is then passed here.

PARAMETER DESCRIPTION
url

The URL to navigate to and capture.

TYPE: str

session_id

ID of an open browser session created with open_session.

TYPE: str

image_type

Image format. Defaults to "png". Use "jpeg" for smaller file sizes.

TYPE: ScreenshotType DEFAULT: 'png'

full_page

When True, captures the full scrollable page instead of just the viewport.

TYPE: bool DEFAULT: False

quality

Image quality (0-100) for JPEG only. Raises if passed with image_type="png".

TYPE: Optional[int] DEFAULT: None

wait

Time in milliseconds to wait after page load before capturing.

TYPE: int | float DEFAULT: 0

wait_selector

Optional CSS selector to wait for before capturing.

TYPE: Optional[str] DEFAULT: None

wait_selector_state

State to wait for the selector.

TYPE: SelectorWaitStates DEFAULT: 'attached'

network_idle

Wait for the page until there are no network connections for at least 500 ms.

TYPE: bool DEFAULT: False

timeout

Timeout in milliseconds for page operations.

TYPE: int | float DEFAULT: 30000

Source code in scrapling/core/ai.py
async def screenshot(
    self,
    url: str,
    session_id: str,
    image_type: ScreenshotType = "png",
    full_page: bool = False,
    quality: Optional[int] = None,
    wait: int | float = 0,
    wait_selector: Optional[str] = None,
    wait_selector_state: SelectorWaitStates = "attached",
    network_idle: bool = False,
    timeout: int | float = 30000,
) -> List[ImageContent | TextContent]:
    """Capture a screenshot of a web page using an existing browser session and return it as an image.
    A browser session must be opened first with `open_session` (either `dynamic` or `stealthy`); the session ID is then passed here.

    :param url: The URL to navigate to and capture.
    :param session_id: ID of an open browser session created with `open_session`.
    :param image_type: Image format. Defaults to "png". Use "jpeg" for smaller file sizes.
    :param full_page: When True, captures the full scrollable page instead of just the viewport.
    :param quality: Image quality (0-100) for JPEG only. Raises if passed with `image_type="png"`.
    :param wait: Time in milliseconds to wait after page load before capturing.
    :param wait_selector: Optional CSS selector to wait for before capturing.
    :param wait_selector_state: State to wait for the selector.
    :param network_idle: Wait for the page until there are no network connections for at least 500 ms.
    :param timeout: Timeout in milliseconds for page operations.
    """
    if quality is not None and image_type != "jpeg":
        raise ValueError("'quality' is only valid when 'image_type' is 'jpeg'.")

    entry = self._get_session(session_id, expected_type=None)
    if entry.session_type == "static":
        raise ValueError(
            f"Session '{session_id}' is a 'static' session, so it can't take screenshots. "
            f"Open a 'dynamic' or 'stealthy' session for that."
        )

    screenshot_kwargs: Dict[str, Any] = {"type": image_type, "full_page": full_page}
    if quality is not None:
        screenshot_kwargs["quality"] = quality

    captured: Dict[str, Any] = {}

    async def _capture(page: Any) -> None:
        try:
            captured["bytes"] = await page.screenshot(**screenshot_kwargs)
            captured["url"] = page.url
        except Exception as exc:
            captured["error"] = exc

    await entry.session.fetch(
        url,
        page_action=_capture,
        wait=wait,
        timeout=timeout,
        network_idle=network_idle,
        wait_selector=wait_selector,
        wait_selector_state=wait_selector_state,
    )

    if "error" in captured:
        raise captured["error"]
    if "bytes" not in captured:
        raise RuntimeError(f"Failed to capture screenshot for {url}")

    image = Image(data=captured["bytes"], format=image_type).to_image_content()
    return [image, TextContent(type="text", text=captured["url"])]

make_request async staticmethod

make_request(
    url,
    method="GET",
    impersonate="chrome",
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    params=None,
    data=None,
    json=None,
    headers=None,
    cookies=None,
    timeout=30,
    follow_redirects="safe",
    max_redirects=30,
    retries=3,
    retry_delay=1,
    proxy=None,
    proxy_auth=None,
    auth=None,
    verify=True,
    http3=False,
    stealthy_headers=True,
)

Make an HTTP request to a URL with any method (GET, POST, PUT, DELETE) and return a structured output of the result. Only suitable for low-mid protection levels.

PARAMETER DESCRIPTION
url

The URL to request.

TYPE: str

method

The HTTP method to use: "GET" (default), "POST", "PUT", or "DELETE".

TYPE: SUPPORTED_HTTP_METHODS DEFAULT: 'GET'

impersonate

Browser version to impersonate its fingerprint. It's using the latest chrome version by default.

TYPE: ImpersonateType DEFAULT: 'chrome'

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

params

Query string parameters for the request.

TYPE: Optional[Dict] DEFAULT: None

data

Form data for the request body. Used with "POST", "PUT", and "DELETE" only.

TYPE: Optional[Dict[str, str] | str] DEFAULT: None

json

A JSON-serializable object for the request body. Used with "POST", "PUT", and "DELETE" only.

TYPE: Optional[Dict | List] DEFAULT: None

headers

Headers to include in the request.

TYPE: Optional[Mapping[str, Optional[str]]] DEFAULT: None

cookies

Cookies to use in the request.

TYPE: Optional[Dict[str, str]] DEFAULT: None

timeout

Number of seconds to wait before timing out.

TYPE: Optional[int | float] DEFAULT: 30

follow_redirects

Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection). Pass True to follow all redirects without restriction.

TYPE: FollowRedirects DEFAULT: 'safe'

max_redirects

Maximum number of redirects. Use -1 for unlimited.

TYPE: int DEFAULT: 30

retries

Number of retry attempts.

TYPE: Optional[int] DEFAULT: 3

retry_delay

Number of seconds to wait between retry attempts.

TYPE: Optional[int] DEFAULT: 1

proxy

Proxy URL to use. Format: "http://username:password@localhost:8030". Cannot be used together with the proxies parameter.

TYPE: Optional[str] DEFAULT: None

proxy_auth

HTTP basic auth for proxy in dictionary format with username and password keys.

TYPE: Optional[Dict[str, str]] DEFAULT: None

auth

HTTP basic auth in dictionary format with username and password keys.

TYPE: Optional[Dict[str, str]] DEFAULT: None

verify

Whether to verify HTTPS certificates.

TYPE: Optional[bool] DEFAULT: True

http3

Whether to use HTTP3. It might be problematic if used it with impersonate.

TYPE: Optional[bool] DEFAULT: False

stealthy_headers

If enabled (default), it creates and adds real browser headers. It also sets a Google referer header.

TYPE: Optional[bool] DEFAULT: True

Source code in scrapling/core/ai.py
@staticmethod
async def make_request(
    url: str,
    method: SUPPORTED_HTTP_METHODS = "GET",
    impersonate: ImpersonateType = "chrome",
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    params: Optional[Dict] = None,
    data: Optional[Dict[str, str] | str] = None,
    json: Optional[Dict | List] = None,
    headers: Optional[Mapping[str, Optional[str]]] = None,
    cookies: Optional[Dict[str, str]] = None,
    timeout: Optional[int | float] = 30,
    follow_redirects: FollowRedirects = "safe",
    max_redirects: int = 30,
    retries: Optional[int] = 3,
    retry_delay: Optional[int] = 1,
    proxy: Optional[str] = None,
    proxy_auth: Optional[Dict[str, str]] = None,
    auth: Optional[Dict[str, str]] = None,
    verify: Optional[bool] = True,
    http3: Optional[bool] = False,
    stealthy_headers: Optional[bool] = True,
) -> ResponseModel:
    """Make an HTTP request to a URL with any method (GET, POST, PUT, DELETE) and return a structured output of the result.
    Only suitable for low-mid protection levels.

    :param url: The URL to request.
    :param method: The HTTP method to use: "GET" (default), "POST", "PUT", or "DELETE".
    :param impersonate: Browser version to impersonate its fingerprint. It's using the latest chrome version by default.
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param params: Query string parameters for the request.
    :param data: Form data for the request body. Used with "POST", "PUT", and "DELETE" only.
    :param json: A JSON-serializable object for the request body. Used with "POST", "PUT", and "DELETE" only.
    :param headers: Headers to include in the request.
    :param cookies: Cookies to use in the request.
    :param timeout: Number of seconds to wait before timing out.
    :param follow_redirects: Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection).
        Pass True to follow all redirects without restriction.
    :param max_redirects: Maximum number of redirects. Use -1 for unlimited.
    :param retries: Number of retry attempts.
    :param retry_delay: Number of seconds to wait between retry attempts.
    :param proxy: Proxy URL to use. Format: "http://username:password@localhost:8030".
                 Cannot be used together with the `proxies` parameter.
    :param proxy_auth: HTTP basic auth for proxy in dictionary format with `username` and `password` keys.
    :param auth: HTTP basic auth in dictionary format with `username` and `password` keys.
    :param verify: Whether to verify HTTPS certificates.
    :param http3: Whether to use HTTP3. It might be problematic if used it with `impersonate`.
    :param stealthy_headers: If enabled (default), it creates and adds real browser headers. It also sets a Google referer header.
    """
    normalized_proxy_auth = _normalize_credentials(proxy_auth)
    normalized_auth = _normalize_credentials(auth)

    request_kwargs: Dict[str, Any] = dict(
        auth=normalized_auth,
        proxy=proxy,
        http3=http3,
        verify=verify,
        params=params,
        headers=headers,
        cookies=cookies,
        timeout=timeout,
        retries=retries,
        proxy_auth=normalized_proxy_auth,
        retry_delay=retry_delay,
        impersonate=impersonate,
        max_redirects=max_redirects,
        follow_redirects=follow_redirects,
        stealthy_headers=stealthy_headers,
    )
    if method != "GET":
        request_kwargs.update(data=data, json=json)

    async with FetcherSession() as session:
        page = await getattr(session, method.lower())(url, **request_kwargs)
        return _translate_response(page, extraction_type, css_selector, main_content_only)

bulk_get async staticmethod

bulk_get(
    urls,
    impersonate="chrome",
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    params=None,
    headers=None,
    cookies=None,
    timeout=30,
    follow_redirects="safe",
    max_redirects=30,
    retries=3,
    retry_delay=1,
    proxy=None,
    proxy_auth=None,
    auth=None,
    verify=True,
    http3=False,
    stealthy_headers=True,
)

Make GET HTTP request to a group of URLs and for each URL, return a structured output of the result. Only suitable for low-mid protection levels.

PARAMETER DESCRIPTION
urls

A list of the URLs to request.

TYPE: List[str]

impersonate

Browser version to impersonate its fingerprint. It's using the latest chrome version by default.

TYPE: ImpersonateType DEFAULT: 'chrome'

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page. Defaults to None.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

params

Query string parameters for the request.

TYPE: Optional[Dict] DEFAULT: None

headers

Headers to include in the request.

TYPE: Optional[Mapping[str, Optional[str]]] DEFAULT: None

cookies

Cookies to use in the request.

TYPE: Optional[Dict[str, str]] DEFAULT: None

timeout

Number of seconds to wait before timing out.

TYPE: Optional[int | float] DEFAULT: 30

follow_redirects

Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection). Pass True to follow all redirects without restriction.

TYPE: FollowRedirects DEFAULT: 'safe'

max_redirects

Maximum number of redirects. Use -1 for unlimited.

TYPE: int DEFAULT: 30

retries

Number of retry attempts.

TYPE: Optional[int] DEFAULT: 3

retry_delay

Number of seconds to wait between retry attempts.

TYPE: Optional[int] DEFAULT: 1

proxy

Proxy URL to use. Format: "http://username:password@localhost:8030". Cannot be used together with the proxies parameter.

TYPE: Optional[str] DEFAULT: None

proxy_auth

HTTP basic auth for proxy in dictionary format with username and password keys.

TYPE: Optional[Dict[str, str]] DEFAULT: None

auth

HTTP basic auth in dictionary format with username and password keys.

TYPE: Optional[Dict[str, str]] DEFAULT: None

verify

Whether to verify HTTPS certificates.

TYPE: Optional[bool] DEFAULT: True

http3

Whether to use HTTP3. It might be problematic if used it with impersonate.

TYPE: Optional[bool] DEFAULT: False

stealthy_headers

If enabled (default), it creates and adds real browser headers. It also sets a Google referer header.

TYPE: Optional[bool] DEFAULT: True

Source code in scrapling/core/ai.py
@staticmethod
async def bulk_get(
    urls: List[str],
    impersonate: ImpersonateType = "chrome",
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    params: Optional[Dict] = None,
    headers: Optional[Mapping[str, Optional[str]]] = None,
    cookies: Optional[Dict[str, str]] = None,
    timeout: Optional[int | float] = 30,
    follow_redirects: FollowRedirects = "safe",
    max_redirects: int = 30,
    retries: Optional[int] = 3,
    retry_delay: Optional[int] = 1,
    proxy: Optional[str] = None,
    proxy_auth: Optional[Dict[str, str]] = None,
    auth: Optional[Dict[str, str]] = None,
    verify: Optional[bool] = True,
    http3: Optional[bool] = False,
    stealthy_headers: Optional[bool] = True,
) -> List[ResponseModel]:
    """Make GET HTTP request to a group of URLs and for each URL, return a structured output of the result.
    Only suitable for low-mid protection levels.

    :param urls: A list of the URLs to request.
    :param impersonate: Browser version to impersonate its fingerprint. It's using the latest chrome version by default.
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page. Defaults to None.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param params: Query string parameters for the request.
    :param headers: Headers to include in the request.
    :param cookies: Cookies to use in the request.
    :param timeout: Number of seconds to wait before timing out.
    :param follow_redirects: Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection).
        Pass True to follow all redirects without restriction.
    :param max_redirects: Maximum number of redirects. Use -1 for unlimited.
    :param retries: Number of retry attempts.
    :param retry_delay: Number of seconds to wait between retry attempts.
    :param proxy: Proxy URL to use. Format: "http://username:password@localhost:8030".
                 Cannot be used together with the `proxies` parameter.
    :param proxy_auth: HTTP basic auth for proxy in dictionary format with `username` and `password` keys.
    :param auth: HTTP basic auth in dictionary format with `username` and `password` keys.
    :param verify: Whether to verify HTTPS certificates.
    :param http3: Whether to use HTTP3. It might be problematic if used it with `impersonate`.
    :param stealthy_headers: If enabled (default), it creates and adds real browser headers. It also sets a Google referer header.
    """
    normalized_proxy_auth = _normalize_credentials(proxy_auth)
    normalized_auth = _normalize_credentials(auth)

    async with FetcherSession() as session:
        tasks: List[Any] = [
            session.get(
                url,
                auth=normalized_auth,
                proxy=proxy,
                http3=http3,
                verify=verify,
                params=params,
                headers=headers,
                cookies=cookies,
                timeout=timeout,
                retries=retries,
                proxy_auth=normalized_proxy_auth,
                retry_delay=retry_delay,
                impersonate=impersonate,
                max_redirects=max_redirects,
                follow_redirects=follow_redirects,
                stealthy_headers=stealthy_headers,
            )
            for url in urls
        ]
        responses = await gather(*tasks)
        return [_translate_response(page, extraction_type, css_selector, main_content_only) for page in responses]

fetch async

fetch(
    url,
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    headless=True,
    google_search=True,
    real_chrome=False,
    wait=0,
    proxy=None,
    timezone_id=None,
    locale=None,
    extra_headers=None,
    useragent=None,
    cdp_url=None,
    executable_path=None,
    timeout=30000,
    disable_resources=False,
    wait_selector=None,
    cookies=None,
    network_idle=False,
    wait_selector_state="attached",
)

Use playwright to open a browser to fetch a URL and return a structured output of the result. Only suitable for low-mid protection levels.

PARAMETER DESCRIPTION
url

The URL to request.

TYPE: str

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

headless

Run the browser in headless/hidden (default), or headful/visible mode.

TYPE: bool DEFAULT: True

disable_resources

Drop requests for unnecessary resources for a speed boost. Requests dropped are of type font, image, media, beacon, object, imageset, texttrack, websocket, csp_report, and stylesheet.

TYPE: bool DEFAULT: False

useragent

Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.

TYPE: Optional[str] DEFAULT: None

cookies

Set cookies for the next request. It should be in a dictionary format that Playwright accepts.

TYPE: Sequence[SetCookieParam] | None DEFAULT: None

network_idle

Wait for the page until there are no network connections for at least 500 ms.

TYPE: bool DEFAULT: False

timeout

The timeout in milliseconds that is used in all operations and waits through the page.

TYPE: int | float DEFAULT: 30000

wait

The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the Response object.

TYPE: int | float DEFAULT: 0

wait_selector

Wait for a specific CSS selector to be in a specific state.

TYPE: Optional[str] DEFAULT: None

timezone_id

Changes the timezone of the browser. Defaults to the system timezone.

TYPE: str | None DEFAULT: None

locale

Specify user locale, for example, en-GB, de-DE, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting rules. Defaults to the system locale.

TYPE: str | None DEFAULT: None

wait_selector_state

The state to wait for the selector given with wait_selector.

TYPE: SelectorWaitStates DEFAULT: 'attached'

real_chrome

If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.

TYPE: bool DEFAULT: False

cdp_url

Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.

TYPE: Optional[str] DEFAULT: None

executable_path

Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.

TYPE: Optional[str] DEFAULT: None

google_search

Enabled by default, Scrapling will set a Google referer header.

TYPE: bool DEFAULT: True

extra_headers

A dictionary of extra headers to add to the request. The referer set by google_search takes priority over the referer set here if used together.

TYPE: Optional[Dict[str, str]] DEFAULT: None

proxy

The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.

TYPE: Optional[str | Dict[str, str]] DEFAULT: None

Source code in scrapling/core/ai.py
async def fetch(
    self,
    url: str,
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    headless: bool = True,  # noqa: F821
    google_search: bool = True,
    real_chrome: bool = False,
    wait: int | float = 0,
    proxy: Optional[str | Dict[str, str]] = None,
    timezone_id: str | None = None,
    locale: str | None = None,
    extra_headers: Optional[Dict[str, str]] = None,
    useragent: Optional[str] = None,
    cdp_url: Optional[str] = None,
    executable_path: Optional[str] = None,
    timeout: int | float = 30000,
    disable_resources: bool = False,
    wait_selector: Optional[str] = None,
    cookies: Sequence[SetCookieParam] | None = None,
    network_idle: bool = False,
    wait_selector_state: SelectorWaitStates = "attached",
) -> ResponseModel:
    """Use playwright to open a browser to fetch a URL and return a structured output of the result.
    Only suitable for low-mid protection levels.

    :param url: The URL to request.
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param headless: Run the browser in headless/hidden (default), or headful/visible mode.
    :param disable_resources: Drop requests for unnecessary resources for a speed boost.
        Requests dropped are of type `font`, `image`, `media`, `beacon`, `object`, `imageset`, `texttrack`, `websocket`, `csp_report`, and `stylesheet`.
    :param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
    :param cookies: Set cookies for the next request. It should be in a dictionary format that Playwright accepts.
    :param network_idle: Wait for the page until there are no network connections for at least 500 ms.
    :param timeout: The timeout in milliseconds that is used in all operations and waits through the page.
    :param wait: The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the ` Response ` object.
    :param wait_selector: Wait for a specific CSS selector to be in a specific state.
    :param timezone_id: Changes the timezone of the browser. Defaults to the system timezone.
    :param locale: Specify user locale, for example, `en-GB`, `de-DE`, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting
        rules. Defaults to the system locale.
    :param wait_selector_state: The state to wait for the selector given with `wait_selector`.
    :param real_chrome: If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.
    :param cdp_url: Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.
    :param executable_path: Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.
    :param google_search: Enabled by default, Scrapling will set a Google referer header.
    :param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
    :param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
    """
    results = await self.bulk_fetch(
        urls=[url],
        extraction_type=extraction_type,
        css_selector=css_selector,
        main_content_only=main_content_only,
        headless=headless,
        google_search=google_search,
        real_chrome=real_chrome,
        wait=wait,
        proxy=proxy,
        timezone_id=timezone_id,
        locale=locale,
        extra_headers=extra_headers,
        useragent=useragent,
        cdp_url=cdp_url,
        executable_path=executable_path,
        timeout=timeout,
        disable_resources=disable_resources,
        wait_selector=wait_selector,
        cookies=cookies,
        network_idle=network_idle,
        wait_selector_state=wait_selector_state,
    )
    return results[0]

bulk_fetch async

bulk_fetch(
    urls,
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    headless=True,
    google_search=True,
    real_chrome=False,
    wait=0,
    proxy=None,
    timezone_id=None,
    locale=None,
    extra_headers=None,
    useragent=None,
    cdp_url=None,
    executable_path=None,
    timeout=30000,
    disable_resources=False,
    wait_selector=None,
    cookies=None,
    network_idle=False,
    wait_selector_state="attached",
)

Use playwright to open a browser, then fetch a group of URLs at the same time, and for each page return a structured output of the result. Only suitable for low-mid protection levels.

PARAMETER DESCRIPTION
urls

A list of the URLs to request. Batches bigger than 50 URLs are fetched through a pool of 50 concurrent pages.

TYPE: List[str]

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

headless

Run the browser in headless/hidden (default), or headful/visible mode.

TYPE: bool DEFAULT: True

disable_resources

Drop requests for unnecessary resources for a speed boost. Requests dropped are of type font, image, media, beacon, object, imageset, texttrack, websocket, csp_report, and stylesheet.

TYPE: bool DEFAULT: False

useragent

Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.

TYPE: Optional[str] DEFAULT: None

cookies

Set cookies for the next request. It should be in a dictionary format that Playwright accepts.

TYPE: Sequence[SetCookieParam] | None DEFAULT: None

network_idle

Wait for the page until there are no network connections for at least 500 ms.

TYPE: bool DEFAULT: False

timeout

The timeout in milliseconds that is used in all operations and waits through the page.

TYPE: int | float DEFAULT: 30000

wait

The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the Response object.

TYPE: int | float DEFAULT: 0

wait_selector

Wait for a specific CSS selector to be in a specific state.

TYPE: Optional[str] DEFAULT: None

timezone_id

Changes the timezone of the browser. Defaults to the system timezone.

TYPE: str | None DEFAULT: None

locale

Specify user locale, for example, en-GB, de-DE, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting rules. Defaults to the system locale.

TYPE: str | None DEFAULT: None

wait_selector_state

The state to wait for the selector given with wait_selector.

TYPE: SelectorWaitStates DEFAULT: 'attached'

real_chrome

If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.

TYPE: bool DEFAULT: False

cdp_url

Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.

TYPE: Optional[str] DEFAULT: None

executable_path

Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.

TYPE: Optional[str] DEFAULT: None

google_search

Enabled by default, Scrapling will set a Google referer header.

TYPE: bool DEFAULT: True

extra_headers

A dictionary of extra headers to add to the request. The referer set by google_search takes priority over the referer set here if used together.

TYPE: Optional[Dict[str, str]] DEFAULT: None

proxy

The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.

TYPE: Optional[str | Dict[str, str]] DEFAULT: None

Source code in scrapling/core/ai.py
async def bulk_fetch(
    self,
    urls: List[str],
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    headless: bool = True,  # noqa: F821
    google_search: bool = True,
    real_chrome: bool = False,
    wait: int | float = 0,
    proxy: Optional[str | Dict[str, str]] = None,
    timezone_id: str | None = None,
    locale: str | None = None,
    extra_headers: Optional[Dict[str, str]] = None,
    useragent: Optional[str] = None,
    cdp_url: Optional[str] = None,
    executable_path: Optional[str] = None,
    timeout: int | float = 30000,
    disable_resources: bool = False,
    wait_selector: Optional[str] = None,
    cookies: Sequence[SetCookieParam] | None = None,
    network_idle: bool = False,
    wait_selector_state: SelectorWaitStates = "attached",
) -> List[ResponseModel]:
    """Use playwright to open a browser, then fetch a group of URLs at the same time, and for each page return a structured output of the result.
    Only suitable for low-mid protection levels.

    :param urls: A list of the URLs to request. Batches bigger than 50 URLs are fetched through a pool of 50 concurrent pages.
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param headless: Run the browser in headless/hidden (default), or headful/visible mode.
    :param disable_resources: Drop requests for unnecessary resources for a speed boost.
        Requests dropped are of type `font`, `image`, `media`, `beacon`, `object`, `imageset`, `texttrack`, `websocket`, `csp_report`, and `stylesheet`.
    :param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
    :param cookies: Set cookies for the next request. It should be in a dictionary format that Playwright accepts.
    :param network_idle: Wait for the page until there are no network connections for at least 500 ms.
    :param timeout: The timeout in milliseconds that is used in all operations and waits through the page.
    :param wait: The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the ` Response ` object.
    :param wait_selector: Wait for a specific CSS selector to be in a specific state.
    :param timezone_id: Changes the timezone of the browser. Defaults to the system timezone.
    :param locale: Specify user locale, for example, `en-GB`, `de-DE`, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting
        rules. Defaults to the system locale.
    :param wait_selector_state: The state to wait for the selector given with `wait_selector`.
    :param real_chrome: If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.
    :param cdp_url: Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.
    :param executable_path: Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.
    :param google_search: Enabled by default, Scrapling will set a Google referer header.
    :param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
    :param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
    """
    async with AsyncDynamicSession(
        wait=wait,
        proxy=proxy,
        locale=locale,
        timeout=timeout,
        cookies=cookies,
        cdp_url=cdp_url,
        headless=headless,
        block_ads=True,
        max_pages=_page_pool_size(urls),
        useragent=useragent,
        timezone_id=timezone_id,
        real_chrome=real_chrome,
        network_idle=network_idle,
        wait_selector=wait_selector,
        google_search=google_search,
        extra_headers=extra_headers,
        executable_path=self._resolve_executable_path(executable_path),
        disable_resources=disable_resources,
        wait_selector_state=wait_selector_state,
    ) as session:
        tasks = [session.fetch(url) for url in urls]
        responses = await gather(*tasks)

    return [_translate_response(page, extraction_type, css_selector, main_content_only) for page in responses]

stealthy_fetch async

stealthy_fetch(
    url,
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    headless=True,
    google_search=True,
    real_chrome=False,
    wait=0,
    proxy=None,
    timezone_id=None,
    locale=None,
    extra_headers=None,
    useragent=None,
    hide_canvas=False,
    cdp_url=None,
    executable_path=None,
    timeout=30000,
    disable_resources=False,
    wait_selector=None,
    cookies=None,
    network_idle=False,
    wait_selector_state="attached",
    block_webrtc=False,
    allow_webgl=True,
    solve_cloudflare=False,
    additional_args=None,
)

Use the stealthy fetcher to fetch a URL and return a structured output of the result. The only fetcher suitable for high-protection websites.

PARAMETER DESCRIPTION
url

The URL to request.

TYPE: str

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

headless

Run the browser in headless/hidden (default), or headful/visible mode.

TYPE: bool DEFAULT: True

disable_resources

Drop requests for unnecessary resources for a speed boost. Requests dropped are of type font, image, media, beacon, object, imageset, texttrack, websocket, csp_report, and stylesheet.

TYPE: bool DEFAULT: False

useragent

Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.

TYPE: Optional[str] DEFAULT: None

cookies

Set cookies for the next request.

TYPE: Sequence[SetCookieParam] | None DEFAULT: None

solve_cloudflare

Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response to you.

TYPE: bool DEFAULT: False

allow_webgl

Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.

TYPE: bool DEFAULT: True

network_idle

Wait for the page until there are no network connections for at least 500 ms.

TYPE: bool DEFAULT: False

wait

The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the Response object.

TYPE: int | float DEFAULT: 0

timeout

The timeout in milliseconds that is used in all operations and waits through the page.

TYPE: int | float DEFAULT: 30000

wait_selector

Wait for a specific CSS selector to be in a specific state.

TYPE: Optional[str] DEFAULT: None

timezone_id

Changes the timezone of the browser. Defaults to the system timezone.

TYPE: str | None DEFAULT: None

locale

Specify user locale, for example, en-GB, de-DE, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting rules. Defaults to the system locale.

TYPE: str | None DEFAULT: None

wait_selector_state

The state to wait for the selector given with wait_selector.

TYPE: SelectorWaitStates DEFAULT: 'attached'

real_chrome

If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.

TYPE: bool DEFAULT: False

hide_canvas

Add random noise to canvas operations to prevent fingerprinting.

TYPE: bool DEFAULT: False

block_webrtc

Forces WebRTC to respect proxy settings to prevent local IP address leak.

TYPE: bool DEFAULT: False

cdp_url

Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.

TYPE: Optional[str] DEFAULT: None

executable_path

Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.

TYPE: Optional[str] DEFAULT: None

google_search

Enabled by default, Scrapling will set a Google referer header.

TYPE: bool DEFAULT: True

extra_headers

A dictionary of extra headers to add to the request. The referer set by google_search takes priority over the referer set here if used together.

TYPE: Optional[Dict[str, str]] DEFAULT: None

proxy

The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.

TYPE: Optional[str | Dict[str, str]] DEFAULT: None

additional_args

Additional arguments to be passed to Playwright's context as additional settings, and it takes higher priority than Scrapling's settings.

TYPE: Optional[Dict] DEFAULT: None

Source code in scrapling/core/ai.py
async def stealthy_fetch(
    self,
    url: str,
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    headless: bool = True,  # noqa: F821
    google_search: bool = True,
    real_chrome: bool = False,
    wait: int | float = 0,
    proxy: Optional[str | Dict[str, str]] = None,
    timezone_id: str | None = None,
    locale: str | None = None,
    extra_headers: Optional[Dict[str, str]] = None,
    useragent: Optional[str] = None,
    hide_canvas: bool = False,
    cdp_url: Optional[str] = None,
    executable_path: Optional[str] = None,
    timeout: int | float = 30000,
    disable_resources: bool = False,
    wait_selector: Optional[str] = None,
    cookies: Sequence[SetCookieParam] | None = None,
    network_idle: bool = False,
    wait_selector_state: SelectorWaitStates = "attached",
    block_webrtc: bool = False,
    allow_webgl: bool = True,
    solve_cloudflare: bool = False,
    additional_args: Optional[Dict] = None,
) -> ResponseModel:
    """Use the stealthy fetcher to fetch a URL and return a structured output of the result.
    The only fetcher suitable for high-protection websites.

    :param url: The URL to request.
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param headless: Run the browser in headless/hidden (default), or headful/visible mode.
    :param disable_resources: Drop requests for unnecessary resources for a speed boost.
        Requests dropped are of type `font`, `image`, `media`, `beacon`, `object`, `imageset`, `texttrack`, `websocket`, `csp_report`, and `stylesheet`.
    :param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
    :param cookies: Set cookies for the next request.
    :param solve_cloudflare: Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response to you.
    :param allow_webgl: Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.
    :param network_idle: Wait for the page until there are no network connections for at least 500 ms.
    :param wait: The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the ` Response ` object.
    :param timeout: The timeout in milliseconds that is used in all operations and waits through the page.
    :param wait_selector: Wait for a specific CSS selector to be in a specific state.
    :param timezone_id: Changes the timezone of the browser. Defaults to the system timezone.
    :param locale: Specify user locale, for example, `en-GB`, `de-DE`, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting
        rules. Defaults to the system locale.
    :param wait_selector_state: The state to wait for the selector given with `wait_selector`.
    :param real_chrome: If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.
    :param hide_canvas: Add random noise to canvas operations to prevent fingerprinting.
    :param block_webrtc: Forces WebRTC to respect proxy settings to prevent local IP address leak.
    :param cdp_url: Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.
    :param executable_path: Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.
    :param google_search: Enabled by default, Scrapling will set a Google referer header.
    :param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
    :param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
    :param additional_args: Additional arguments to be passed to Playwright's context as additional settings, and it takes higher priority than Scrapling's settings.
    """
    results = await self.bulk_stealthy_fetch(
        urls=[url],
        extraction_type=extraction_type,
        css_selector=css_selector,
        main_content_only=main_content_only,
        headless=headless,
        google_search=google_search,
        real_chrome=real_chrome,
        wait=wait,
        proxy=proxy,
        timezone_id=timezone_id,
        locale=locale,
        extra_headers=extra_headers,
        useragent=useragent,
        hide_canvas=hide_canvas,
        cdp_url=cdp_url,
        executable_path=executable_path,
        timeout=timeout,
        disable_resources=disable_resources,
        wait_selector=wait_selector,
        cookies=cookies,
        network_idle=network_idle,
        wait_selector_state=wait_selector_state,
        block_webrtc=block_webrtc,
        allow_webgl=allow_webgl,
        solve_cloudflare=solve_cloudflare,
        additional_args=additional_args,
    )
    return results[0]

bulk_stealthy_fetch async

bulk_stealthy_fetch(
    urls,
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    headless=True,
    google_search=True,
    real_chrome=False,
    wait=0,
    proxy=None,
    timezone_id=None,
    locale=None,
    extra_headers=None,
    useragent=None,
    hide_canvas=False,
    cdp_url=None,
    executable_path=None,
    timeout=30000,
    disable_resources=False,
    wait_selector=None,
    cookies=None,
    network_idle=False,
    wait_selector_state="attached",
    block_webrtc=False,
    allow_webgl=True,
    solve_cloudflare=False,
    additional_args=None,
)

Use the stealthy fetcher to fetch a group of URLs at the same time, and for each page return a structured output of the result. The only fetcher suitable for high-protection websites.

PARAMETER DESCRIPTION
urls

A list of the URLs to request. Batches bigger than 50 URLs are fetched through a pool of 50 concurrent pages.

TYPE: List[str]

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

headless

Run the browser in headless/hidden (default), or headful/visible mode.

TYPE: bool DEFAULT: True

disable_resources

Drop requests for unnecessary resources for a speed boost. Requests dropped are of type font, image, media, beacon, object, imageset, texttrack, websocket, csp_report, and stylesheet.

TYPE: bool DEFAULT: False

useragent

Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.

TYPE: Optional[str] DEFAULT: None

cookies

Set cookies for the next request.

TYPE: Sequence[SetCookieParam] | None DEFAULT: None

solve_cloudflare

Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response to you.

TYPE: bool DEFAULT: False

allow_webgl

Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.

TYPE: bool DEFAULT: True

network_idle

Wait for the page until there are no network connections for at least 500 ms.

TYPE: bool DEFAULT: False

wait

The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the Response object.

TYPE: int | float DEFAULT: 0

timeout

The timeout in milliseconds that is used in all operations and waits through the page.

TYPE: int | float DEFAULT: 30000

wait_selector

Wait for a specific CSS selector to be in a specific state.

TYPE: Optional[str] DEFAULT: None

timezone_id

Changes the timezone of the browser. Defaults to the system timezone.

TYPE: str | None DEFAULT: None

locale

Specify user locale, for example, en-GB, de-DE, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting rules. Defaults to the system locale.

TYPE: str | None DEFAULT: None

wait_selector_state

The state to wait for the selector given with wait_selector.

TYPE: SelectorWaitStates DEFAULT: 'attached'

real_chrome

If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.

TYPE: bool DEFAULT: False

hide_canvas

Add random noise to canvas operations to prevent fingerprinting.

TYPE: bool DEFAULT: False

block_webrtc

Forces WebRTC to respect proxy settings to prevent local IP address leak.

TYPE: bool DEFAULT: False

cdp_url

Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.

TYPE: Optional[str] DEFAULT: None

executable_path

Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.

TYPE: Optional[str] DEFAULT: None

google_search

Enabled by default, Scrapling will set a Google referer header.

TYPE: bool DEFAULT: True

extra_headers

A dictionary of extra headers to add to the request. The referer set by google_search takes priority over the referer set here if used together.

TYPE: Optional[Dict[str, str]] DEFAULT: None

proxy

The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.

TYPE: Optional[str | Dict[str, str]] DEFAULT: None

additional_args

Additional arguments to be passed to Playwright's context as additional settings, and it takes higher priority than Scrapling's settings.

TYPE: Optional[Dict] DEFAULT: None

Source code in scrapling/core/ai.py
async def bulk_stealthy_fetch(
    self,
    urls: List[str],
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    headless: bool = True,  # noqa: F821
    google_search: bool = True,
    real_chrome: bool = False,
    wait: int | float = 0,
    proxy: Optional[str | Dict[str, str]] = None,
    timezone_id: str | None = None,
    locale: str | None = None,
    extra_headers: Optional[Dict[str, str]] = None,
    useragent: Optional[str] = None,
    hide_canvas: bool = False,
    cdp_url: Optional[str] = None,
    executable_path: Optional[str] = None,
    timeout: int | float = 30000,
    disable_resources: bool = False,
    wait_selector: Optional[str] = None,
    cookies: Sequence[SetCookieParam] | None = None,
    network_idle: bool = False,
    wait_selector_state: SelectorWaitStates = "attached",
    block_webrtc: bool = False,
    allow_webgl: bool = True,
    solve_cloudflare: bool = False,
    additional_args: Optional[Dict] = None,
) -> List[ResponseModel]:
    """Use the stealthy fetcher to fetch a group of URLs at the same time, and for each page return a structured output of the result.
    The only fetcher suitable for high-protection websites.

    :param urls: A list of the URLs to request. Batches bigger than 50 URLs are fetched through a pool of 50 concurrent pages.
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param headless: Run the browser in headless/hidden (default), or headful/visible mode.
    :param disable_resources: Drop requests for unnecessary resources for a speed boost.
        Requests dropped are of type `font`, `image`, `media`, `beacon`, `object`, `imageset`, `texttrack`, `websocket`, `csp_report`, and `stylesheet`.
    :param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
    :param cookies: Set cookies for the next request.
    :param solve_cloudflare: Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response to you.
    :param allow_webgl: Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.
    :param network_idle: Wait for the page until there are no network connections for at least 500 ms.
    :param wait: The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the ` Response ` object.
    :param timeout: The timeout in milliseconds that is used in all operations and waits through the page.
    :param wait_selector: Wait for a specific CSS selector to be in a specific state.
    :param timezone_id: Changes the timezone of the browser. Defaults to the system timezone.
    :param locale: Specify user locale, for example, `en-GB`, `de-DE`, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting
        rules. Defaults to the system locale.
    :param wait_selector_state: The state to wait for the selector given with `wait_selector`.
    :param real_chrome: If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.
    :param hide_canvas: Add random noise to canvas operations to prevent fingerprinting.
    :param block_webrtc: Forces WebRTC to respect proxy settings to prevent local IP address leak.
    :param cdp_url: Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.
    :param executable_path: Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this request.
    :param google_search: Enabled by default, Scrapling will set a Google referer header.
    :param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
    :param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
    :param additional_args: Additional arguments to be passed to Playwright's context as additional settings, and it takes higher priority than Scrapling's settings.
    """
    async with AsyncStealthySession(
        wait=wait,
        proxy=proxy,
        locale=locale,
        cdp_url=cdp_url,
        timeout=timeout,
        cookies=cookies,
        headless=headless,
        block_ads=True,
        max_pages=_page_pool_size(urls),
        useragent=useragent,
        timezone_id=timezone_id,
        real_chrome=real_chrome,
        hide_canvas=hide_canvas,
        allow_webgl=allow_webgl,
        network_idle=network_idle,
        block_webrtc=block_webrtc,
        wait_selector=wait_selector,
        google_search=google_search,
        extra_headers=extra_headers,
        executable_path=self._resolve_executable_path(executable_path),
        additional_args=additional_args,
        solve_cloudflare=solve_cloudflare,
        disable_resources=disable_resources,
        wait_selector_state=wait_selector_state,
    ) as session:
        tasks = [session.fetch(url) for url in urls]
        responses = await gather(*tasks)

    return [_translate_response(page, extraction_type, css_selector, main_content_only) for page in responses]

session_fetch async

session_fetch(
    url,
    session_id,
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    wait=0,
    timeout=30000,
    google_search=True,
    network_idle=False,
    load_dom=True,
    disable_resources=False,
    wait_selector=None,
    wait_selector_state="attached",
    extra_headers=None,
    blocked_domains=None,
    solve_cloudflare=False,
)

Fetch a URL through a browser session previously opened with open_session and return a structured output of the result. The session (dynamic or stealthy) holds the browser-level configuration; every option here applies to this request only, with the defaults shown.

PARAMETER DESCRIPTION
url

The URL to request.

TYPE: str

session_id

ID of an open browser session created with open_session.

TYPE: str

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

wait

The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the Response object.

TYPE: int | float DEFAULT: 0

timeout

The timeout in milliseconds that is used in all operations and waits through the page.

TYPE: int | float DEFAULT: 30000

google_search

Enabled by default, Scrapling will set a Google referer header.

TYPE: bool DEFAULT: True

network_idle

Wait for the page until there are no network connections for at least 500 ms.

TYPE: bool DEFAULT: False

load_dom

Enabled by default, wait for all JavaScript on the page to fully load and execute.

TYPE: bool DEFAULT: True

disable_resources

Drop requests for unnecessary resources for a speed boost. Requests dropped are of type font, image, media, beacon, object, imageset, texttrack, websocket, csp_report, and stylesheet.

TYPE: bool DEFAULT: False

wait_selector

Wait for a specific CSS selector to be in a specific state.

TYPE: Optional[str] DEFAULT: None

wait_selector_state

The state to wait for the selector given with wait_selector.

TYPE: SelectorWaitStates DEFAULT: 'attached'

extra_headers

A dictionary of extra headers to add to the request. The referer set by google_search takes priority over the referer set here if used together.

TYPE: Optional[Dict[str, str]] DEFAULT: None

blocked_domains

A list of domain names to block requests to for this request. Subdomains are also matched.

TYPE: Optional[Set[str]] DEFAULT: None

solve_cloudflare

(Stealthy sessions only) Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response.

TYPE: bool DEFAULT: False

Source code in scrapling/core/ai.py
async def session_fetch(
    self,
    url: str,
    session_id: str,
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    wait: int | float = 0,
    timeout: int | float = 30000,
    google_search: bool = True,
    network_idle: bool = False,
    load_dom: bool = True,
    disable_resources: bool = False,
    wait_selector: Optional[str] = None,
    wait_selector_state: SelectorWaitStates = "attached",
    extra_headers: Optional[Dict[str, str]] = None,
    blocked_domains: Optional[Set[str]] = None,
    solve_cloudflare: bool = False,
) -> ResponseModel:
    """Fetch a URL through a browser session previously opened with `open_session` and return a structured output of the result.
    The session (dynamic or stealthy) holds the browser-level configuration; every option here applies to this request only, with the defaults shown.

    :param url: The URL to request.
    :param session_id: ID of an open browser session created with `open_session`.
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param wait: The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the `Response` object.
    :param timeout: The timeout in milliseconds that is used in all operations and waits through the page.
    :param google_search: Enabled by default, Scrapling will set a Google referer header.
    :param network_idle: Wait for the page until there are no network connections for at least 500 ms.
    :param load_dom: Enabled by default, wait for all JavaScript on the page to fully load and execute.
    :param disable_resources: Drop requests for unnecessary resources for a speed boost.
        Requests dropped are of type `font`, `image`, `media`, `beacon`, `object`, `imageset`, `texttrack`, `websocket`, `csp_report`, and `stylesheet`.
    :param wait_selector: Wait for a specific CSS selector to be in a specific state.
    :param wait_selector_state: The state to wait for the selector given with `wait_selector`.
    :param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
    :param blocked_domains: A list of domain names to block requests to for this request. Subdomains are also matched.
    :param solve_cloudflare: (Stealthy sessions only) Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response.
    """
    entry = self._get_session(session_id, expected_type=None)
    if entry.session_type == "static":
        raise ValueError(
            f"Session '{session_id}' is a 'static' session. Use `session_make_request` with it instead."
        )
    if solve_cloudflare and entry.session_type != "stealthy":
        raise ValueError(
            f"Session '{session_id}' is a '{entry.session_type}' session, so it can't solve Cloudflare "
            f"challenges. Open a 'stealthy' session for that."
        )

    fetch_keys = _STEALTH_FETCH_KEYS if entry.session_type == "stealthy" else _PLAYWRIGHT_FETCH_KEYS
    fetch_params = dict(
        wait=wait,
        timeout=timeout,
        google_search=google_search,
        network_idle=network_idle,
        load_dom=load_dom,
        disable_resources=disable_resources,
        wait_selector=wait_selector,
        wait_selector_state=wait_selector_state,
        extra_headers=extra_headers,
        blocked_domains=blocked_domains,
        solve_cloudflare=solve_cloudflare,
    )
    page = await entry.session.fetch(
        url, **{name: value for name, value in fetch_params.items() if name in fetch_keys}
    )
    return _translate_response(page, extraction_type, css_selector, main_content_only)

session_make_request async

session_make_request(
    url,
    session_id,
    method="GET",
    extraction_type="markdown",
    css_selector=None,
    main_content_only=True,
    params=None,
    data=None,
    json=None,
    headers=None,
    cookies=None,
    timeout=30,
    follow_redirects="safe",
    max_redirects=30,
    retries=3,
    retry_delay=1,
    auth=None,
    verify=True,
    http3=False,
    stealthy_headers=True,
)

Make an HTTP request with any method (GET, POST, PUT, DELETE) through a requests session previously opened with open_request_session, keeping its cookies, connections, and browser fingerprint across calls. The session holds the impersonation and proxy configuration; every option here applies to this request only, with the defaults shown.

PARAMETER DESCRIPTION
url

The URL to request.

TYPE: str

session_id

ID of an open requests session created with open_request_session.

TYPE: str

method

The HTTP method to use: "GET" (default), "POST", "PUT", or "DELETE".

TYPE: SUPPORTED_HTTP_METHODS DEFAULT: 'GET'

extraction_type

The type of content to extract from the page: "markdown", "html", or "text".

TYPE: extraction_types DEFAULT: 'markdown'

css_selector

CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.

TYPE: Optional[str] DEFAULT: None

main_content_only

Whether to extract only the main content of the page. The main content here is the data inside the <body> tag.

TYPE: bool DEFAULT: True

params

Query string parameters for the request.

TYPE: Optional[Dict] DEFAULT: None

data

Form data for the request body. Used with "POST", "PUT", and "DELETE" only.

TYPE: Optional[Dict[str, str] | str] DEFAULT: None

json

A JSON-serializable object for the request body. Used with "POST", "PUT", and "DELETE" only.

TYPE: Optional[Dict | List] DEFAULT: None

headers

Headers to include in the request.

TYPE: Optional[Mapping[str, Optional[str]]] DEFAULT: None

cookies

Cookies to use in the request.

TYPE: Optional[Dict[str, str]] DEFAULT: None

timeout

Number of seconds to wait before timing out.

TYPE: Optional[int | float] DEFAULT: 30

follow_redirects

Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection). Pass True to follow all redirects without restriction.

TYPE: FollowRedirects DEFAULT: 'safe'

max_redirects

Maximum number of redirects. Use -1 for unlimited.

TYPE: int DEFAULT: 30

retries

Number of retry attempts.

TYPE: Optional[int] DEFAULT: 3

retry_delay

Number of seconds to wait between retry attempts.

TYPE: Optional[int] DEFAULT: 1

auth

HTTP basic auth in dictionary format with username and password keys.

TYPE: Optional[Dict[str, str]] DEFAULT: None

verify

Whether to verify HTTPS certificates.

TYPE: Optional[bool] DEFAULT: True

http3

Whether to use HTTP3. It might be problematic if used it with impersonate.

TYPE: Optional[bool] DEFAULT: False

stealthy_headers

If enabled (default), it creates and adds real browser headers. It also sets a Google referer header.

TYPE: Optional[bool] DEFAULT: True

Source code in scrapling/core/ai.py
async def session_make_request(
    self,
    url: str,
    session_id: str,
    method: SUPPORTED_HTTP_METHODS = "GET",
    extraction_type: extraction_types = "markdown",
    css_selector: Optional[str] = None,
    main_content_only: bool = True,
    params: Optional[Dict] = None,
    data: Optional[Dict[str, str] | str] = None,
    json: Optional[Dict | List] = None,
    headers: Optional[Mapping[str, Optional[str]]] = None,
    cookies: Optional[Dict[str, str]] = None,
    timeout: Optional[int | float] = 30,
    follow_redirects: FollowRedirects = "safe",
    max_redirects: int = 30,
    retries: Optional[int] = 3,
    retry_delay: Optional[int] = 1,
    auth: Optional[Dict[str, str]] = None,
    verify: Optional[bool] = True,
    http3: Optional[bool] = False,
    stealthy_headers: Optional[bool] = True,
) -> ResponseModel:
    """Make an HTTP request with any method (GET, POST, PUT, DELETE) through a requests session previously opened
    with `open_request_session`, keeping its cookies, connections, and browser fingerprint across calls. The session
    holds the impersonation and proxy configuration; every option here applies to this request only, with the defaults shown.

    :param url: The URL to request.
    :param session_id: ID of an open requests session created with `open_request_session`.
    :param method: The HTTP method to use: "GET" (default), "POST", "PUT", or "DELETE".
    :param extraction_type: The type of content to extract from the page: "markdown", "html", or "text".
    :param css_selector: CSS selector to extract the content from the page. If main_content_only is True, then it will be executed on the main content of the page.
    :param main_content_only: Whether to extract only the main content of the page. The main content here is the data inside the `<body>` tag.
    :param params: Query string parameters for the request.
    :param data: Form data for the request body. Used with "POST", "PUT", and "DELETE" only.
    :param json: A JSON-serializable object for the request body. Used with "POST", "PUT", and "DELETE" only.
    :param headers: Headers to include in the request.
    :param cookies: Cookies to use in the request.
    :param timeout: Number of seconds to wait before timing out.
    :param follow_redirects: Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection).
        Pass True to follow all redirects without restriction.
    :param max_redirects: Maximum number of redirects. Use -1 for unlimited.
    :param retries: Number of retry attempts.
    :param retry_delay: Number of seconds to wait between retry attempts.
    :param auth: HTTP basic auth in dictionary format with `username` and `password` keys.
    :param verify: Whether to verify HTTPS certificates.
    :param http3: Whether to use HTTP3. It might be problematic if used it with `impersonate`.
    :param stealthy_headers: If enabled (default), it creates and adds real browser headers. It also sets a Google referer header.
    """
    entry = self._get_session(session_id, expected_type="static")

    request_kwargs: Dict[str, Any] = dict(
        auth=_normalize_credentials(auth),
        http3=http3,
        verify=verify,
        params=params,
        headers=headers,
        cookies=cookies,
        timeout=timeout,
        retries=retries,
        retry_delay=retry_delay,
        max_redirects=max_redirects,
        follow_redirects=follow_redirects,
        stealthy_headers=stealthy_headers,
    )
    if method != "GET":
        request_kwargs.update(data=data, json=json)

    page = await getattr(entry.session._client, method.lower())(url, **request_kwargs)
    return _translate_response(page, extraction_type, css_selector, main_content_only)

serve

serve(
    http,
    host,
    port,
    allowed_hosts=(),
    allow_unauthenticated=False,
)

Serve the MCP server.

PARAMETER DESCRIPTION
http

Serve over the streamable-http transport instead of stdio.

TYPE: bool

host

The host to bind to when http is enabled.

TYPE: str

port

The port to bind to when http is enabled.

TYPE: int

allowed_hosts

Host names to accept, which turns on DNS-rebinding protection.

TYPE: Sequence[str] DEFAULT: ()

allow_unauthenticated

Start the streamable-http transport without a token. The transport requires authentication by default, so this is the explicit opt-out.

TYPE: bool DEFAULT: False

Source code in scrapling/core/ai.py
def serve(
    self,
    http: bool,
    host: str,
    port: int,
    allowed_hosts: Sequence[str] = (),
    allow_unauthenticated: bool = False,
):
    """Serve the MCP server.

    :param http: Serve over the streamable-http transport instead of stdio.
    :param host: The host to bind to when `http` is enabled.
    :param port: The port to bind to when `http` is enabled.
    :param allowed_hosts: Host names to accept, which turns on DNS-rebinding protection.
    :param allow_unauthenticated: Start the streamable-http transport without a token. The transport
        requires authentication by default, so this is the explicit opt-out.
    """
    if not http:
        if self._auth_token:
            log.warning(
                "The authentication token only applies to the streamable-http transport, so it's ignored with stdio."
            )
    elif self._auth_token:
        if allow_unauthenticated:
            log.warning(
                "An authentication token was given, so it takes precedence and the server still requires it."
            )
    elif not allow_unauthenticated:
        raise ValueError(
            f"Refusing to serve the MCP server over HTTP without authentication because anyone who can reach "
            f"{host}:{port} would be able to use every tool, including fetching arbitrary URLs from this machine. "
            f"Pass `--auth-token` (or set the {MCP_AUTH_TOKEN_ENV} environment variable) to require a bearer "
            f"token, or `--no-auth` to serve it unauthenticated anyway."
        )
    else:
        log.warning(
            f"The MCP server is running over HTTP without authentication, so anyone who can reach "
            f"{host}:{port} can use every tool, including fetching arbitrary URLs from this machine."
        )

    server = self._build_server(host, port)
    if http:
        server.run(
            transport="streamable-http",
            host=host,
            port=port,
            transport_security=self._transport_security(allowed_hosts),
        )
    else:
        server.run()