human_requests¶
Submodules¶
Classes¶
A dataclass containing the parsed URL components. |
|
Represents an HTTP method. |
|
Spoofing settings for curl_cffi and browser header generation. |
|
Policy for selecting a profile in ImpersonationConfig |
|
curl_cffi.AsyncSession + BrowserMaster + CookieManager. |
Package Contents¶
- class HttpMethod(*args, **kwds)[source]¶
Represents an HTTP method.
- GET = 'GET'¶
Retrieves data from a server. It only reads data and does not modify it.
- POST = 'POST'¶
Submits data to a server to create a new resource. It can also be used to update existing resources.
- PUT = 'PUT'¶
Updates a existing resource on a server. It can also be used to create a new resource.
- PATCH = 'PATCH'¶
Updates a existing resource on a server. It only updates the fields that are provided in the request body.
- DELETE = 'DELETE'¶
Deletes a resource from a server.
- HEAD = 'HEAD'¶
Retrieves metadata from a server. It only reads the headers and does not return the response body.
- OPTIONS = 'OPTIONS'¶
Provides information about the HTTP methods supported by a server. It can be used for Cross-Origin Resource Sharing (CORS) request.
- class ImpersonationConfig[source]¶
Spoofing settings for curl_cffi and browser header generation.
Example:
cfg = ImpersonationConfig( policy=Policy.RANDOM_EACH_REQUEST, browser_family=["chrome", "edge"], min_version=120, geo_country="DE", sync_with_engine=True, )
- browser_family: str | Sequence[str] | None = None¶
Browser family (chrome, edge, opera, firefox, safari)
- custom_filter: Callable[[str], bool]¶
Custom script for filtering impersonation profiles. Must return a bool
- sync_with_engine: bool = True¶
Restrict to the current Playwright engine family (chromium, firefox, webkit), or camoufox=firefox
- class Policy(*args, **kwds)[source]¶
Policy for selecting a profile in ImpersonationConfig
- INIT_RANDOM¶
Profile is selected at session creation and then does not change
- RANDOM_EACH_REQUEST¶
Profile is selected for every request
- class Session(
- *,
- timeout: float = 15.0,
- headless: bool = True,
- browser: human_requests.browsers.Engine = 'chromium',
- spoof: ImpersonationConfig | None = None,
- playwright_stealth: bool = True,
- page_retry: int = 2,
- direct_retry: int = 1,
- browser_launch_opts: Mapping[str, Any] = {},
- proxy: str | None = None,
curl_cffi.AsyncSession + BrowserMaster + CookieManager.
- browser_name: human_requests.browsers.Engine = 'chromium'¶
Current browser (chromium/firefox/webkit/camoufox/patchright).
- spoof: ImpersonationConfig¶
Impersonation settings (user-agent, TLS, client-hello).
- playwright_stealth: bool = True¶
Hide certain automation signatures? Implemented via JS injection. Some sites may detect this.
- proxy: str | dict[str, str] | None = None¶
Proxy server, one of:
URL string in the form: schema://user:pass@host:port
playwright-like dict
- cookies: CookieManager¶
Storage of all active cookies.
- async request(
- method: HttpMethod | str,
- url: str,
- *,
- headers: Mapping[str, str] | None = None,
- retry: int | None = None,
- **kwargs: Any,
Standard fast request via curl_cffi. You must provide either an HttpMethod or its string representation, as well as a URL.
Optionally, you can pass additional headers.
Extra parameters can be passed through **kwargs to curl_cffi.AsyncSession.request (see their documentation for details). Retries are performed ONLY on cffi Timeout:
curl_cffi.requests.exceptions.Timeout
.
- async goto_page(
- url: str,
- *,
- wait_until: Literal['commit', 'load', 'domcontentloaded', 'networkidle'] = 'commit',
- retry: int | None = None,
Opens a page in the browser using a one-time context. Retries perform a “soft reload” without recreating the context.
- async __aexit__(
- exc_type: type[BaseException] | None,
- exc: BaseException | None,
- tb: TracebackType | None,