human_requests.abstraction

Submodules

Classes

URL

A dataclass containing the parsed URL components.

HttpMethod

Represents an HTTP method.

Proxy

Универсальный класс для работы с прокси в двух форматах:

FetchRequest

Represents all the data passed in the request.

FetchResponse

Represents the response of a request.

Package Contents

class URL[source]

A dataclass containing the parsed URL components.

full_url: str

The full URL.

base_url: str = ''

The base URL, without query parameters.

secure: bool = False

Whether the URL is secure (https/wss).

protocol: str = ''

The protocol of the URL.

path: str = ''

The path of the URL.

domain_with_port: str = ''

The domain of the URL with port.

domain: str = ''

The domain of the URL.

port: int | None = None

The port of the URL.

params: dict[str, list[str]]

A dictionary of query parameters.

__post_init__() None[source]
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 Proxy(
proxy: str | Dict[str, Any] | None = None,
*,
server: str | None = None,
username: str | None = None,
password: str | None = None,
)[source]

Универсальный класс для работы с прокси в двух форматах: 1. Строковый: ‘http://user:pass@host:port’ или ‘socks5://host:port’ 2. Playwright dict: {

‘server’: ‘http://host:port’, ‘username’: ‘user’, ‘password’: ‘pass’

}

as_dict() Dict[str, Any][source]

Возвращает прокси в формате Playwright

as_str(include_auth: bool = True) str[source]

Возвращает прокси в строковом формате. Если include_auth=False — без логина и пароля.

__repr__() str[source]
__bool__() bool[source]
class FetchRequest[source]

Represents all the data passed in the request.

page: HumanPage

The page that made the request.

method: HttpMethod

The method used in the request.

url: URL

The URL of the request.

headers: dict

The headers of the request.

body: str | list | dict | None

The body of the request.

class FetchResponse[source]

Represents the response of a request.

request: FetchRequest

The request that was made.

page: HumanPage

The page that made the request.

url: URL

The URL of the response. Due to redirects, it can differ from request.url.

headers: dict

The headers of the response.

raw: bytes

The raw body of the response.

status_code: int

The status code of the response.

status_text: str

Человеко-читаемое представление status_code

redirected: bool

Был ли ответ сформировапн в следствии редиректа

type: Literal['basic', 'cors', 'error', 'opaque', 'opaqueredirect']
duration: float

The duration of the request in seconds.

end_time: float

Current time in seconds since the Epoch.

property text: str

The body of the response.

json() dict | list[source]
seconds_ago() float[source]

How long ago was the request?

async render(
retry: int = 2,
timeout: float | None = None,
wait_until: Literal['commit', 'load', 'domcontentloaded', 'networkidle'] = 'commit',
referer: str | None = None,
) HumanPage[source]

Renders the response content in the current browser. It will look like we requested it through the browser from the beginning.

Recommended to use in cases when the server returns a JS challenge instead of a response.