summaryrefslogtreecommitdiffstats
path: root/g4f/requests.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2023-12-07 07:18:05 +0100
committerGitHub <noreply@github.com>2023-12-07 07:18:05 +0100
commit484b96d850aca9b9144f3b8dd2fb502b25356c22 (patch)
treeb10fe200193cfdbe0ee25714df49959c01c6265f /g4f/requests.py
parentUpdate Pi.py (diff)
downloadgpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.gz
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.bz2
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.lz
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.xz
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.zst
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.zip
Diffstat (limited to '')
-rw-r--r--g4f/requests.py28
1 files changed, 2 insertions, 26 deletions
diff --git a/g4f/requests.py b/g4f/requests.py
index 8cf70ac9..00ab9488 100644
--- a/g4f/requests.py
+++ b/g4f/requests.py
@@ -6,10 +6,7 @@ from functools import partialmethod
from typing import AsyncGenerator
from urllib.parse import urlparse
from curl_cffi.requests import AsyncSession, Session, Response
-from .webdriver import WebDriver, WebDriverSession
-from selenium.webdriver.common.by import By
-from selenium.webdriver.support.ui import WebDriverWait
-from selenium.webdriver.support import expected_conditions as EC
+from .webdriver import WebDriver, WebDriverSession, bypass_cloudflare
class StreamResponse:
def __init__(self, inner: Response) -> None:
@@ -58,28 +55,7 @@ class StreamSession(AsyncSession):
def get_session_from_browser(url: str, webdriver: WebDriver = None, proxy: str = None, timeout: int = 120):
with WebDriverSession(webdriver, "", proxy=proxy, virtual_display=True) as driver:
- driver.get(url)
-
- # Is cloudflare protection
- if driver.find_element(By.TAG_NAME, "body").get_attribute("class") == "no-js":
- try:
- # Click button in iframe
- WebDriverWait(driver, 5).until(
- EC.presence_of_element_located((By.CSS_SELECTOR, "#turnstile-wrapper iframe"))
- )
- driver.switch_to.frame(driver.find_element(By.CSS_SELECTOR, "#turnstile-wrapper iframe"))
- WebDriverWait(driver, 5).until(
- EC.presence_of_element_located((By.CSS_SELECTOR, "#challenge-stage input"))
- )
- driver.find_element(By.CSS_SELECTOR, "#challenge-stage input").click()
- except:
- pass
- finally:
- driver.switch_to.default_content()
- # No cloudflare protection
- WebDriverWait(driver, timeout).until(
- EC.presence_of_element_located((By.CSS_SELECTOR, "body:not(.no-js)"))
- )
+ bypass_cloudflare(driver, url, timeout)
cookies = dict([(cookie["name"], cookie["value"]) for cookie in driver.get_cookies()])
user_agent = driver.execute_script("return navigator.userAgent")