From e2e5452fe227bfa4ab34ee07045983932c12905f Mon Sep 17 00:00:00 2001 From: Kennedy Oliveira Date: Sat, 27 Jan 2024 20:08:59 -0300 Subject: [PATCH] Add wait time after challenge --- README.md | 1 + src/dtos.py | 3 +++ src/flaresolverr_service.py | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index b5208fc..7e73376 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ session. When you no longer need to use a session you should make sure to close | cookies | Optional. Will be used by the headless browser. Eg: `"cookies": [{"name": "cookie1", "value": "value1"}, {"name": "cookie2", "value": "value2"}]`. | | returnOnlyCookies | Optional, default false. Only returns the cookies. Response data, headers and other parts of the response are removed. | | proxy | Optional, default disabled. Eg: `"proxy": {"url": "http://127.0.0.1:8888"}`. You must include the proxy schema in the URL: `http://`, `socks4://` or `socks5://`. Authorization (username/password) is not supported. (When the `session` parameter is set, the proxy is ignored; a session specific proxy can be set in `sessions.create`.) | +| waitInSeconds | Optional, default none, how long to wait with the page open after solving the challenge and before returning the results, useful to allow it to load dynamic content. | > **Warning** > If you want to use Cloudflare clearance cookie in your scripts, make sure you use the FlareSolverr User-Agent too. If they don't match you will see the challenge. diff --git a/src/dtos.py b/src/dtos.py index 1e9aace..6ec5842 100644 --- a/src/dtos.py +++ b/src/dtos.py @@ -43,6 +43,9 @@ class V1RequestBase(object): returnOnlyCookies: bool = None download: bool = None # deprecated v2.0.0, not used returnRawHtml: bool = None # deprecated v2.0.0, not used + # Wait the specified amount in seconds after resolving the challenge and before returning the response + # this can be useful for loading dynamic content of the page + waitInSeconds: int = None def __init__(self, _dict): self.__dict__.update(_dict) diff --git a/src/flaresolverr_service.py b/src/flaresolverr_service.py index 6cef3e4..09c01f9 100644 --- a/src/flaresolverr_service.py +++ b/src/flaresolverr_service.py @@ -398,6 +398,11 @@ def _evil_logic(req: V1RequestBase, driver: WebDriver, method: str) -> Challenge if not req.returnOnlyCookies: challenge_res.headers = {} # todo: fix, selenium not provides this info + + if req.waitInSeconds and req.waitInSeconds > 0: + logging.info("Waiting " + str(req.waitInSeconds) + " seconds before returning the response...") + time.sleep(req.waitInSeconds) + challenge_res.response = driver.page_source res.result = challenge_res