Package: hrequests
hrequestsHrequests (human requests) is a simple, configurable, feature-rich, replacement for the Python requests library.✨ FeaturesSeamless transition between HTTP and headless browsing 💻Integrated fast HTML parser 🚀High performance network concurrency with goroutines & gevent 🚀Replication of browser TLS fingerprints 🚀JavaScript rendering 🚀Supports HTTP/2 🚀Realistic browser header generation 🚀JSON serializing up to 10x faster than the standard library 🚀💻 Browser crawlingSimple & uncomplicated browser automationHuman-like cursor movement and typingChrome and Firefox extension supportFull page screenshotsProxy supportHeadless and headful supportNo CORS restrictions⚡ MoreHigh performance ✨Minimal dependence on the python standard librariesHTTP backend written in GoAutomatic gzip & brotli decodeWritten with type safety100% threadsafe ❤️InstallationInstall via pip:pipinstall-Uhrequests[all]python-mhrequestsinstallOr, install without headless browsing supportIgnore the[all]option if you don't want headless browsing support:pipinstall-UhrequestsDocumentationSimple UsageSessionsConcurrent & Lazy RequestsHTML ParsingBrowser AutomationSimple UsageHere is an example of a simplegetrequest:>>>resp=hrequests.get('https://www.google.com/')Requests are sent throughbogdanfinn's tls-clientto spoof the TLS client fingerprint. This is done automatically, and is completely transparent to the user.Other request methods includepost,put,delete,head,options, andpatch.TheResponseobject is a near 1:1 replica of therequests.Responseobject, with some additional attributes.ParametersParameters:
    url (Union[str, Iterable[str]]): URL or list of URLs to request.
    data (Union[str, bytes, bytearray, dict], optional): Data to send to request. Defaults to None.
    files (Dict[str, Union[BufferedReader, tuple]], optional): Data to send to request. Defaults to None.
    headers (dict, optional): Dictionary of HTTP headers to send with the request. Defaults to None.
    params (dict, optional): Dictionary of URL parameters to append to the URL. Defaults to None.
    cookies (Union[RequestsCookieJar, dict, list], optional): Dict or CookieJar to send. Defaults to None.
    json (dict, optional): Json to send in the request body. Defaults to None.
    allow_redirects (bool, optional): Allow request to redirect. Defaults to True.
    history (bool, optional): Remember request history. Defaults to False.
    verify (bool, optional): Verify the server's TLS certificate. Defaults to True.
    timeout (float, optional): Timeout in seconds. Defaults to 30.
    proxy (str, optional): Proxy URL. Defaults to None.
    nohup (bool, optional): Run the request in the background. Defaults to False.
    <Additionally includes all parameters from `hrequests.Session` if a session was not specified>

Returns:
    hrequests.response.Response: Response objectPropertiesGet the response url:>>>resp.url:str'https://www.google.com/'Check if the request was successful:>>>resp.status_code:int200>>>resp.reason:str'OK'>>>resp.ok:boolTrue>>>bool(resp)TrueGetting the response body:>>>resp.text:str'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta charset="UTF-8"><meta content="origin" name="referrer"><m...'>>>resp.content:bytesb'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta charset="UTF-8"><meta content="origin" name="referrer"><m...'>>>resp.encoding:str'UTF-8'Parse the response body as JSON:>>>resp.json():Union[dict,list]{'somedata':True}Get the elapsed time of the request:>>>resp.elapsed:datetime.timedeltadatetime.timedelta(microseconds=77768)Get the response cookies:>>>resp.cookies:RequestsCookieJar<RequestsCookieJar[Cookie(version=0,name='1P_JAR',value='2023-07-05-20',port=None,port_specified=False,domain='.google.com',domain_specified=True...Get the response headers:>>>resp.headers:CaseInsensitiveDict{'Alt-Svc':'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000','Cache-Control':'private, max-age=0','Content-Encoding':'br','Content-Length':'51288','Content-Security-Policy-Report-Only':"object-src 'none';base-uri 'seSessionsCreating a new Chrome Session object:>>>session=hrequests.Session()# version randomized by default>>>session=hrequests.Session('chrome',version=120)ParametersParameters:
    browser (Literal['firefox', 'chrome'], optional): Browser to use. Default is 'chrome'.
    version (int, optional): Version of the browser to use. Browser must be specified. Default is randomized.
    os (Literal['win', 'mac', 'lin'], optional): OS to use in header. Default is randomized.
    headers (dict, optional): Dictionary of HTTP headers to send with the request. Default is generated from `browser` and `os`.
    verify (bool, optional): Verify the server's TLS certificate. Defaults to True.
    timeout (float, optional): Default timeout in seconds. Defaults to 30.
    proxy (str, optional): Proxy URL. Defaults to None.
    cookies (Union[RequestsCookieJar, dict, list], optional): Cookie Jar, or cookie list/dict to send. Defaults to None.
    certificate_pinning (Dict[str, List[str]], optional): Certificate pinning. Defaults to None.
    disable_ipv6 (bool, optional): Disable IPv6. Defaults to False.
    detect_encoding (bool, optional): Detect encoding. Defaults to True.
    ja3_string (str, optional): JA3 string. Defaults to None.
    h2_settings (dict, optional): HTTP/2 settings. Defaults to None.
    additional_decode (str, optional): Decode response body with "gzip" or "br". Defaults to None.
    pseudo_header_order (list, optional): Pseudo header order. Defaults to None.
    priority_frames (list, optional): Priority frames. Defaults to None.
    header_order (list, optional): Header order. Defaults to None.
    force_http1 (bool, optional): Force HTTP/1. Defaults to False.
    catch_panics (bool, optional): Catch panics. Defaults to False.
    debug (bool, optional): Debug mode. Defaults to False.Browsers can also be created through thefirefoxandchromeshortcuts:>>>session=hrequests.firefox.Session()>>>session=hrequests.chrome.Session()ParametersParameters:
    version (int, optional): Version of the browser to use. Browser must be specified. Default is randomized.
    os (Literal['win', 'mac', 'lin'], optional): OS to use in header. Default is randomized.
    headers (dict, optional): Dictionary of HTTP headers to send with the request. Default is generated from `browser` and `os`.
    verify (bool, optional): Verify the server's TLS certificate. Defaults to True.
    timeout (float, optional): Default timeout in seconds. Defaults to 30.
    proxy (str, optional): Proxy URL. Defaults to None.
    cookies (Union[RequestsCookieJar, dict, list], optional): Cookie Jar, or cookie list/dict to send. Defaults to None.
    certificate_pinning (Dict[str, List[str]], optional): Certificate pinning. Defaults to None.
    disable_ipv6 (bool, optional): Disable IPv6. Defaults to False.
    detect_encoding (bool, optional): Detect encoding. Defaults to True.
    ja3_string (str, optional): JA3 string. Defaults to None.
    h2_settings (dict, optional): HTTP/2 settings. Defaults to None.
    additional_decode (str, optional): Decode response body with "gzip" or "br". Defaults to None.
    pseudo_header_order (list, optional): Pseudo header order. Defaults to None.
    priority_frames (list, optional): Priority frames. Defaults to None.
    header_order (list, optional): Header order. Defaults to None.
    force_http1 (bool, optional): Force HTTP/1. Defaults to False.
    catch_panics (bool, optional): Catch panics. Defaults to False.
    debug (bool, optional): Debug mode. Defaults to False.oscan be'win','mac', or'lin'. Default is randomized.>>>session=hrequests.chrome.Session(os='mac')This will automatically generate headers based on the browser name and OS:>>>session.headers{'Accept':'*/*','Connection':'keep-alive','User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4; rv:60.2.2) Gecko/20100101 Firefox/60.2.2','Accept-Encoding':'gzip, deflate, br','Pragma':'no-cache'}Why is the browser version in the header different than the TLS browser version?Website bot detection systems typically do not correlate the TLS fingerprint browser version with the browser header.By adding more randomization to our headers, we can make our requests appear to be coming from a larger number of clients. We can make it seem like our requests are coming from a larger number of clients. This makes it harder for websites to identify and block our requests based on a consistent browser version.PropertiesHere is a simple get request. This is a wrapper aroundhrequests.get. The only difference is that the session cookies are updated with each request. Creating sessions are recommended for making multiple requests to the same domain.>>>resp=session.get('https://www.google.com/')Session cookies update with each request:>>>session.cookies:RequestsCookieJar<RequestsCookieJar[Cookie(version=0,name='1P_JAR',value='2023-07-05-20',port=None,port_specified=False,domain='.google.com',domain_specified=True...Regenerate headers for a different OS:>>>session.os='win'>>>session.headers:CaseInsensitiveDict{'Accept':'*/*','Connection':'keep-alive','User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0.3) Gecko/20100101 Firefox/66.0.3','Accept-Encoding':'gzip, deflate, br','Accept-Language':'en-US;q=0.5,en;q=0.3','Cache-Control':'max-age=0','DNT':'1','Upgrade-Insecure-Requests':'1','Pragma':'no-cache'}Closing SessionsSessions can also be closed to free memory:>>>session.close()Alternatively, sessions can be used as context managers:withhrequests.Session()assession:resp=session.get('https://www.google.com/')print(resp)Concurrent & Lazy RequestsNohup RequestsSimilar to Unix's nohup command,nohuprequests are sent in the background.Adding thenohup=Truekeyword argument will return aLazyTLSRequestobject. This will send the request immediately, but doesn't wait for the response to be ready until an attribute of the response is accessed.resp1=hrequests.get('https://www.google.com/',nohup=True)resp2=hrequests.get('https://www.google.com/',nohup=True)resp1andresp2are sent concurrently. They willneverpause the current thread, unless an attribute of the response is accessed:print('Resp 1:',resp1.reason)# will wait for resp1 to finish, if it hasn't alreadyprint('Resp 2:',resp2.reason)# will wait for resp2 to finish, if it hasn't alreadyThis is useful for sending requests in the background that aren't needed until later.Note: Innohup, a new thread is created for each request. For larger scale concurrency, please consider the following:Easy ConcurrencyYou can pass an array/iterator of links to the request methods to send them concurrently. This wraps aroundhrequests.map:>>>hrequests.get(['https://google.com/','https://github.com/'])(<Response[200]>,<Response[200]>)This also works withnohup:>>>resps=hrequests.get(['https://google.com/','https://github.com/'],nohup=True)>>>resps(<LazyResponse[Pending]>,<LazyResponse[Pending]>)>>># Sometime later...>>>resps(<Response[200]>,<Response[200]>)Grequests-style ConcurrencyThe methodsasync_get,async_post, etc. will create an unsent request. This levereges gevent, making itblazing fast.ParametersParameters:
    url (str): URL to send request to
    data (Union[str, bytes, bytearray, dict], optional): Data to send to request. Defaults to None.
    files (Dict[str, Union[BufferedReader, tuple]], optional): Data to send to request. Defaults to None.
    headers (dict, optional): Dictionary of HTTP headers to send with the request. Defaults to None.
    params (dict, optional): Dictionary of URL parameters to append to the URL. Defaults to None.
    cookies (Union[RequestsCookieJar, dict, list], optional): Dict or CookieJar to send. Defaults to None.
    json (dict, optional): Json to send in the request body. Defaults to None.
    allow_redirects (bool, optional): Allow request to redirect. Defaults to True.
    history (bool, optional): Remember request history. Defaults to False.
    verify (bool, optional): Verify the server's TLS certificate. Defaults to True.
    timeout (float, optional): Timeout in seconds. Defaults to 30.
    proxy (str, optional): Proxy URL. Defaults to None.
    <Additionally includes all parameters from `hrequests.Session` if a session was not specified>

Returns:
    hrequests.response.Response: Response objectAsync requests are evaluated onhrequests.map,hrequests.imap, orhrequests.imap_enum.This functionality is similar togrequests. Unlike grequests,monkey patchingis not required because this does not rely on the standard python SSL library.Create a set of unsent Requests:>>>reqs=[...hrequests.async_get('https://www.google.com/',browser='firefox'),...hrequests.async_get('https://www.duckduckgo.com/'),...hrequests.async_get('https://www.yahoo.com/')...]mapSend them all at the same time using map:>>>hrequests.map(reqs,size=3)[<Response[200]>,<Response[200]>,<Response[200]>]ParametersConcurrently converts a list of Requests to Responses.
Parameters:
    requests - a collection of Request objects.
    size - Specifies the number of requests to make at a time. If None, no throttling occurs.
    exception_handler - Callback function, called when exception occurred. Params: Request, Exception
    timeout - Gevent joinall timeout in seconds. (Note: unrelated to requests timeout)

Returns:
    A list of Response objects.imapimapreturns a generator that yields responses as they come in:>>>forrespinhrequests.imap(reqs,size=3):...print(resp)<Response[200]><Response[200]><Response[200]>ParametersConcurrently converts a generator object of Requests to a generator of Responses.

Parameters:
    requests - a generator or sequence of Request objects.
    size - Specifies the number of requests to make at a time. default is 2
    exception_handler - Callback function, called when exception occurred. Params: Request, Exception

Yields:
    Response objects.imap_enumreturns a generator that yields a tuple of(index, response)as they come in. Theindexis the index of the request in the original list:>>>forindex,respinhrequests.imap_enum(reqs,size=3):...print(index,resp)(1,<Response[200]>)(0,<Response[200]>)(2,<Response[200]>)ParametersLike imap, but yields tuple of original request index and response object
Unlike imap, failed results and responses from exception handlers that return None are not ignored. Instead, a
tuple of (index, None) is yielded.
Responses are still in arbitrary order.

Parameters:
    requests - a sequence of Request objects.
    size - Specifies the number of requests to make at a time. default is 2
    exception_handler - Callback function, called when exception occurred. Params: Request, Exception

Yields:
    (index, Response) tuples.Exception HandlingTo handle timeouts or any other exception during the connection of the request, you can add an optional exception handler that will be called with the request and exception inside the main thread.>>>defexception_handler(request,exception):...returnf'Response failed:{exception}'>>>bad_reqs=[...hrequests.async_get('http://httpbin.org/delay/5',timeout=1),...hrequests.async_get('http://fakedomain/'),...hrequests.async_get('http://example.com/'),...]>>>hrequests.map(bad_reqs,size=3,exception_handler=exception_handler)['Response failed: Connection error','Response failed: Connection error',<Response[200]>]The value returned by the exception handler will be used in place of the response in the result list.If an exception handler isn't specified, the default yield type ishrequests.FailedResponse.HTML ParsingHTML scraping is based offselectolax, which isover 25x fasterthan bs4. This functionality is inspired byrequests-html.LibraryTime (1e5 trials)BeautifulSoup452.6PyQuery7.5selectolax1.9The HTML parser can be accessed through thehtmlattribute of the response object:>>>resp=session.get('https://python.org/')>>>resp.html<HTMLurl='https://www.python.org/'>Parsing pageGrab a list of all links on the page, as-is (anchors excluded):>>>resp.html.links{'//docs.python.org/3/tutorial/','/about/apps/','https://github.com/python/pythondotorg/issues','/accounts/login/','/dev/peps/','/about/legal/',...Grab a list of all links on the page, in absolute form (anchors excluded):>>>resp.html.absolute_links{'https://github.com/python/pythondotorg/issues','https://docs.python.org/3/tutorial/','https://www.python.org/about/success/','http://feedproxy.g...Search for text on the page:>>>resp.html.search('Python is a{}language')[0]programmingSelecting elementsSelect an element using a CSS Selector:>>>about=resp.html.find('#about')ParametersGiven a CSS Selector, returns a list of
:class:`Element <Element>` objects or a single one.

Parameters:
    selector: CSS Selector to use.
    clean: Whether or not to sanitize the found HTML of ``<script>`` and ``<style>``
    containing: If specified, only return elements that contain the provided text.
    first: Whether or not to return just the first result.
    raise_exception: Raise an exception if no elements are found. Default is True.
    _encoding: The encoding format.

Returns:
    A list of :class:`Element <Element>` objects or a single one.

Example CSS Selectors:
- ``a``
- ``a.someClass``
- ``a#someID``
- ``a[target=_blank]``
See W3School's `CSS Selectors Reference
<https://www.w3schools.com/cssref/css_selectors.asp>`_
for more details.
If ``first`` is ``True``, only returns the first
:class:`Element <Element>` found.Introspecting elementsGrab an Element's text contents:>>>print(about.text)AboutApplicationsQuotesGettingStartedHelpPythonBrochureGetting an Element's attributes:>>>about.attrs{'id':'about','class':('tier-1','element-1'),'aria-haspopup':'true'}>>>about.id'about'Get an Element's raw HTML:>>>about.html'<li aria-haspopup="true" class="tier-1 element-1 " id="about">\n<a class="" href="/about/" title="">About</a>\n<ul aria-hidden="true" class="subnav menu" role="menu">\n<li class="tier-2 element-1" role="treeitem"><a href="/about/apps/" title="">Applications</a></li>\n<li class="tier-2 element-2" role="treeitem"><a href="/about/quotes/" title="">Quotes</a></li>\n<li class="tier-2 element-3" role="treeitem"><a href="/about/gettingstarted/" title="">Getting Started</a></li>\n<li class="tier-2 element-4" role="treeitem"><a href="/about/help/" title="">Help</a></li>\n<li class="tier-2 element-5" role="treeitem"><a href="http://brochure.getpython.info/" title="">Python Brochure</a></li>\n</ul>\n</li>'Select Elements within Elements:>>>about.find_all('a')[<Element'a'href='/about/'title=''class=''>,<Element'a'href='/about/apps/'title=''>,<Element'a'href='/about/quotes/'title=''>,<Element'a'href='/about/gettingstarted/'title=''>,<Element'a'href='/about/help/'title=''>,<Element'a'href='http://brochure.getpython.info/'title=''>]>>>about.find('a')<Element'a'href='/about/'title=''class=''>Searching by HTML attributes:>>>about.find('il',role='treeitem')<Element'li'role='treeitem'class=('tier-2','element-1')>Search for links within an element:>>>about.absolute_links{'http://brochure.getpython.info/','https://www.python.org/about/gettingstarted/','https://www.python.org/about/','https://www.python.org/about/quotes/','https://www.python.org/about/help/','https://www.python.org/about/apps/'}Browser AutomationHrequests supports both Firefox and Chrome browsers, headless and headful sessions, and browser addons/extensions:Browser support tableChrome supports both Manifest v2/v3 extensions. Firefox only supports Manifest v2 extensions.Only Firefox supports CloudFlare WAFs.BrowserMV2MV3Cloudfare WAFsFirefox:heavy_check_mark::x::heavy_check_mark:Chrome:heavy_check_mark::heavy_check_mark::x:UsageYou can spawn aBrowserSessioninstance by calling it:>>>page=hrequests.BrowserSession()# headless=True by defaultParametersParameters:
    headless (bool, optional): Whether to run the browser in headless mode. Defaults to True.
    session (hrequests.session.TLSSession, optional): Session to use for headers, cookies, etc.
    resp (hrequests.response.Response, optional): Response to update with cookies, headers, etc.
    proxy (str, optional): Proxy to use for the browser. Example: http://1.2.3.4:8080
    mock_human (bool, optional): Whether to emulate human behavior. Defaults to False.
    browser (Literal['firefox', 'chrome'], optional): Generate useragent headers for a specific browser
    os (Literal['win', 'mac', 'lin'], optional): Generate headers for a specific OS
    extensions (Union[str, Iterable[str]], optional): Path to a folder of unpacked extensions, or a list of paths to unpacked extensionsBy default,BrowserSessionreturns a Chrome browser.To create a Firefox session, use the chrome shortcut instead:>>>page=hrequests.firefox.BrowserSession()BrowserSessionis entirely safe to use across threads.Render an existing ResponseResponses have a.render()method. This will render the contents of the response in a browser page.Once the page is closed, the Response content and the Response's session cookies will be updated.Simple usageRendered browser sessions will use the browser set in the initial request.You can set a request's browser with thebrowserparameter in thehrequests.getmethod:>>>resp=hrequests.get('https://example.com',browser='chrome')Or by setting thebrowserparameter of thehrequests.Sessionobject:>>>session=hrequests.Session(browser='chrome')>>>resp=session.get('https://example.com')Example - submitting a login form:>>>session=hrequests.Session(browser='chrome')>>>resp=session.get('https://www.somewebsite.com/')>>>withresp.render(mock_human=True)aspage:...page.type('.input#username','myuser')...page.type('.input#password','p4ssw0rd')...page.click('#submit')# `session` & `resp` now have updated cookies, content, etc.Or, without a context manager>>>session=hrequests.Session(browser='chrome')>>>resp=session.get('https://www.somewebsite.com/')>>>page=resp.render(mock_human=True)>>>page.type('.input#username','myuser')>>>page.type('.input#password','p4ssw0rd')>>>page.click('#submit')>>>page.close()# must close the page when done!Themock_humanparameter will emulate human-like behavior. This includes easing and randomizing mouse movements, and randomizing typing speed. This functionality is based onbotright.ParametersParameters:
    headless (bool, optional): Whether to run the browser in headless mode. Defaults to False.
    mock_human (bool, optional): Whether to emulate human behavior. Defaults to False.
    extensions (Union[str, Iterable[str]], optional): Path to a folder of unpacked extensions, or a list of paths to unpacked extensionsPropertiesCookies are inherited from the session:>>>page.cookies:RequestsCookieJar# cookies are inherited from the session<RequestsCookieJar[Cookie(version=0,name='1P_JAR',value='2023-07-05-20',port=None,port_specified=False,domain='.somewebsite.com',domain_specified=True...Pulling page dataGet current page url:>>>page.url:strhttps://www.somewebsite.com/Get page content:>>>page.text:str'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world\'s information, including webpag'>>>page.content:bytesb'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world\'s information, including webpag'Get the status of the last navigation:>>>page.status_code:int200>>>page.reason:str'OK'Parsing HTML from the page content:>>>page.html.find_all('a')[<Element'a'href='/about/'title=''class=''>,<Element'a'href='/about/apps/'title=''>,...]>>>page.html.find('a')<Element'a'href='/about/'title=''class=''>,<Element'a'href='/about/apps/'title=''>Take a screenshot of the page:>>>page.screenshot(path='screenshot.png')ParametersTake a screenshot of the page

Parameters:
    selector (str, optional): CSS selector to screenshot
    path (str, optional): Path to save screenshot to. Defaults to None.
    full_page (bool): Whether to take a screenshot of the full scrollable page. Cannot be used with selector. Defaults to False.

Returns:
    Optional[bytes]: Returns the screenshot buffer, if `path` was not providedNavigate the browserNavigate to a url:>>>page.url='https://bing.com'# or use goto>>>page.goto('https://bing.com')Navigate through page history:>>>page.back()>>>page.forward()Controlling elementsClick an element:>>>page.click('#my-button')# or through the html parser>>>page.html.find('#my-button').click()ParametersParameters:
    selector (str): CSS selector to click.
    button (Literal['left', 'right', 'middle'], optional): Mouse button to click. Defaults to 'left'.
    count (int, optional): Number of clicks. Defaults to 1.
    timeout (float, optional): Timeout in seconds. Defaults to 30.
    wait_after (bool, optional): Wait for a page event before continuing. Defaults to True.Hover over an element:>>>page.hover('.dropbtn')# or through the html parser>>>page.html.find('.dropbtn').hover()ParametersParameters:
    selector (str): CSS selector to hover over
    modifiers (List[Literal['Alt', 'Control', 'Meta', 'Shift']], optional): Modifier keys to press. Defaults to None.
    timeout (float, optional): Timeout in seconds. Defaults to 90.Type text into an element:>>>page.type('#my-input','Hello world!')# or through the html parser>>>page.html.find('#my-input').type('Hello world!')ParametersParameters:
    selector (str): CSS selector to type in
    text (str): Text to type
    delay (int, optional): Delay between keypresses in ms. On mock_human, this is randomized by 50%. Defaults to 50.
    timeout (float, optional): Timeout in seconds. Defaults to 30.Drag and drop an element:>>>page.dragTo('#source-selector','#target-selector')# or through the html parser>>>page.html.find('#source-selector').dragTo('#target-selector')ParametersParameters:
    source (str): Source to drag from
    target (str): Target to drop to
    timeout (float, optional): Timeout in seconds. Defaults to 30.
    wait_after (bool, optional): Wait for a page event before continuing. Defaults to False.
    check (bool, optional): Check if an element is draggable before running. Defaults to False.

Throws:
    hrequests.exceptions.BrowserTimeoutException: If timeout is reachedCheck page elementsCheck if a selector is visible and enabled:>>>page.isVisible('#my-selector'):bool>>>page.isEnabled('#my-selector'):boolParametersParameters:
    selector (str): Selector to checkEvaluate and return a script:>>>page.evaluate('selector => document.querySelector(selector).checked','#my-selector')ParametersParameters:
    script (str): Javascript to evaluate in the page
    arg (str, optional): Argument to pass into the javascript functionAwaiting events>>>page.awaitNavigation()ParametersParameters:
    timeout (float, optional): Timeout in seconds. Defaults to 30.

Throws:
    hrequests.exceptions.BrowserTimeoutException: If timeout is reachedWait for a script or function to return a truthy value:>>>page.awaitScript('selector => document.querySelector(selector).value === 100','#progress')ParametersParameters:
    script (str): Script to evaluate
    arg (str, optional): Argument to pass to script
    timeout (float, optional): Timeout in seconds. Defaults to 30.

Throws:
    hrequests.exceptions.BrowserTimeoutException: If timeout is reachedWait for the URL to match:>>>page.awaitUrl(re.compile(r'https?://www\.google\.com/.*'),timeout=10)ParametersParameters:
    url (Union[str, Pattern[str], Callable[[str], bool]]) - URL to match for
    timeout (float, optional): Timeout in seconds. Defaults to 30.

Throws:
    hrequests.exceptions.BrowserTimeoutException: If timeout is reachedWait for an element to exist on the page:>>>page.awaitSelector('#my-selector')# or through the html parser>>>page.html.find('#my-selector').awaitSelector()ParametersParameters:
    selector (str): Selector to wait for
    timeout (float, optional): Timeout in seconds. Defaults to 30.

Throws:
    hrequests.exceptions.BrowserTimeoutException: If timeout is reachedWait for an element to be enabled:>>>page.awaitEnabled('#my-selector')# or through the html parser>>>page.html.find('#my-selector').awaitEnabled()ParametersParameters:
    selector (str): Selector to wait for
    timeout (float, optional): Timeout in seconds. Defaults to 30.

Throws:
    hrequests.exceptions.BrowserTimeoutException: If timeout is reachedScreenshot an element:>>>page.screenshot('#my-selector',path='screenshot.png')# or through the html parser>>>page.html.find('#my-selector').screenshot('selector.png')ParametersScreenshot an element

Parameters:
    selector (str, optional): CSS selector to screenshot
    path (str, optional): Path to save screenshot to. Defaults to None.
    full_page (bool): Whether to take a screenshot of the full scrollable page. Cannot be used with selector. Defaults to False.

Returns:
    Optional[bytes]: Returns the screenshot buffer, if `path` was not providedAdding Firefox/Chrome extensionsFirefox/Chrome extensions can be easily imported into a browser session. Some potentially useful extensions include:hektCaptcha- Hcaptcha solver (Chrome)uBlock Origin- Ad & popup blocker (Chrome,Firefox)FastForward- Bypass & skip link redirects (Chrome,Firefox)Note: Firefox extensions areFirefox-only, and Chrome extensions areChrome-only.If you plan on using Firefox-specific or Chrome-specific extensions, make sure to set yourbrowserparameter to the correct browser before rendering the page:# when dealing with captchas, make sure to use firefox>>>resp=hrequests.get('https://accounts.hcaptcha.com/demo',browser='firefox')Extensions are added with theextensionsparameter:This can be an list of absolute paths to unpacked extensions:withresp.render(extensions=['C:\\extensions\\hektcaptcha','C:\\extensions\\ublockorigin']):Or a folder containing the unpacked extensions:withresp.render(extensions='C:\\extentions'):Note that these need to beunpackedextensions. You can unpack a.crxfile by changing the file extension to.zipand extracting the contents.Here is an usage example of using a captcha solver:>>>resp=hrequests.get('https://accounts.hcaptcha.com/demo',browser='firefox')>>>withresp.render(extensions=['C:\\extensions\\hektcaptcha'])aspage:...page.awaitSelector('.hcaptcha-success')# wait for captcha to finish...page.click('input[type=submit]')Requests & ResponsesRequests can also be sent within browser sessions. These operate the same as the standardhrequests.request, and will use the browser's cookies and headers. TheBrowserSessioncookies will be updated with each request.This returns a normalResponseobject:>>>resp=page.get('https://duckduckgo.com')ParametersParameters:
    url (str): URL to send request to
    params (dict, optional): Dictionary of URL parameters to append to the URL. Defaults to None.
    data (Union[str, dict], optional): Data to send to request. Defaults to None.
    headers (dict, optional): Dictionary of HTTP headers to send with the request. Defaults to None.
    form (dict, optional): Form data to send with the request. Defaults to None.
    multipart (dict, optional): Multipart data to send with the request. Defaults to None.
    timeout (float, optional): Timeout in seconds. Defaults to 30.
    verify (bool, optional): Verify the server's TLS certificate. Defaults to True.
    max_redirects (int, optional): Maximum number of redirects to follow. Defaults to None.

Throws:
    hrequests.exceptions.BrowserTimeoutException: If timeout is reached

Returns:
    hrequests.response.Response: Response objectOther methods includepost,put,delete,head, andpatch.Closing the pageTheBrowserSessionobject must be closed when finished. This will close the browser, update the response data, and merge new cookies with the session cookies.>>>page.close()Note that this is automatically done when using a context manager.Session cookies are updated:>>>session.cookies:RequestsCookieJar<RequestsCookieJar[Cookie(version=0,name='MUID',value='123456789',port=None,port_specified=False,domain='.bing.com',domain_specified=True,domain_initial_dot=True...Response data is updated:>>>resp.url:str'https://www.bing.com/?toWww=1&redig=823778234657823652376438'>>>resp.content:Union[bytes,str]'<!DOCTYPE html><html lang="en" dir="ltr"><head><meta name="theme-color" content="#4F4F4F"><meta name="description" content="Bing helps you turn inform...Other ways to create a Browser SessionYou can use.renderto spawn aBrowserSessionobject directly from a url:# Using a Session:>>>page=session.render('https://google.com')# Or without a session at all:>>>page=hrequests.render('https://google.com')Make sure to close allBrowserSessionobjects when done!>>>page.close()