Add wait time after challenge

This commit is contained in:
Kennedy Oliveira 2024-01-27 20:08:59 -03:00
parent df06d13cf8
commit e2e5452fe2
No known key found for this signature in database
3 changed files with 9 additions and 0 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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