Closed
Description
I'm sorry for may be being stupid, but..
Bug only on ubuntu 22.04. On Windows 11 no issues!
I have been struggling with this problem for several days:
THIS CODE WORKS ON UBUNTU 22.04:
from selenium import webdriver
from selenium_stealth import stealth
import seleniumbase as sb
def initialize_driver():
try:
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("--headless")
driver = sb.Driver(browser='chrome', headless=True, uc=True)
wait = webdriver.Chrome.implicitly_wait(driver,500.00)
stealth(driver,
languages=["en-EN", "en"],
vendor="Google Inc.",
platform="Win64",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
wait=wait
)
time.sleep(3)
return driver
except:
return None
THIS CODE ALWAYS FAILS ON UBUNTU 22.04:
def initialize_driver(account_number, cookies_file, url, proxy, attempt=1):
if attempt > 5:
return None
try:
driver = sb.Driver(browser='chrome', headless=True, uc=True, proxy=proxy)
wait = webdriver.Chrome.implicitly_wait(driver,500.00)
stealth(driver,
languages=["en-EN", "en"],
vendor="Google Inc.",
platform="Win64",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
wait=wait
)
driver.get(url)
time.sleep(3)
with open(cookies_file, 'r') as f:
cookies = json.load(f)
current_domain = driver.current_url
for cookie in cookies:
if 'sameSite' in cookie and cookie['sameSite'] not in ['Strict', 'Lax', 'None']:
del cookie['sameSite']
if 'domain' in cookie:
if current_domain.find(cookie['domain']) != -1: # Check if the cookie domain is in the current domain
driver.add_cookie(cookie)
driver.refresh()
time.sleep(3)
try:
wait = WebDriverWait(driver, 2)
wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(normalize-space(), 'Enter or registrate')]")))
driver.quit()
return initialize_driver(account_number, cookies_file, url, proxy, attempt + 1)
except Exception as e:
print(e)
return driver
except Exception as e:
print(e)
driver.quit()
return None
I was debugging alot. On Windows 11 no issues!
Only this code can go through Cloudflare on a target site
Thank you!