seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5.3k stars 973 forks source link

Unable to pass cloudflare in linux server #3195

Closed Code-With-Hashim closed 1 week ago

Code-With-Hashim commented 1 week ago

Hi I'm trying to bypass Cloudflare in my AWS Linux server but it's not bypassing it, I tried every method that is required for bypassing it this is my sample code

import os
from seleniumbase import SB
import time
import pyautogui
import random
# from pyvirtualdisplay.display import Display
# disp = Display(visible=True, size=(1366, 768), backend="xvfb", use_xauth=True)
# disp.start()

# os.environ['DISPLAY'] = ':99'

# print(os.environ['DISPLAY'], 'after')
# import Xlib.display
# pyautogui._pyautogui_x11._display = Xlib.display.Display(os.environ['DISPLAY'])

def verify_success(sb):
    sb.assert_element('img[alt="Logo Assembly"]', timeout=4)
    sb.sleep(3)

ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
with SB(uc=True, headed=True, disable_features="UserAgentClientHint", agent=ua, incognito=True, xvfb=True) as sb:
    sb.uc_open_with_reconnect("https://modijiurl.com/fBUFTv", 3)
    tab_handles = sb.driver.window_handles
    print(len(tab_handles))
    if (len(tab_handles) >= 2):
        for tab in tab_handles:
            print(tab)
        sb.switch_to_window(0)
        print('switched')
    print(sb.get_current_url())
    # driver_version = sb.driver.capabilities['chrome']['chromedriverVersion']  # For Chrome
        # For Firefox, use:
        # driver_version = self.driver.capabilities['moz:geckodriverVersion']

    if sb.is_element_visible("iframe"):
        sb.switch_to_frame("iframe")
        sb.execute_script('document.querySelector("input").focus()')
        sb.disconnect()
        print('Click..')
        pyautogui.press(" ")
        sb.driver.reconnect(10)

    # sb.uc_gui_click_x_y(x, y, timeframe=0.25)

    sb.uc_gui_click_captcha(frame="iframe", retry=False, blind=False)
    # driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False)
    # driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False)

    # sb.uc_gui_handle_captcha(frame="iframe")
    sb.uc_gui_click_captcha()
    print("connect")
    random_number = random.randint(1000, 9999)
    filename = f"screenshot_{random_number}.png"
    sb.save_screenshot(filename)
    print('End.')

    time.sleep(10)
    print(sb.get_current_url())
    sb.uc_gui_click_captcha()
    time.sleep(10)
    print(sb.get_current_url())

`

Anyone let me know what I can do for run on the Linux server it's working in my local system screenshot_6198 screenshot_9741 This is some screenshot I hope it will help you It's great help if someone give me an answer for that

mdmintz commented 1 week ago

From the examples, this is a basic script for bypassing CF on Linux:

from seleniumbase import SB

with SB(uc=True, xvfb=True) as sb:
    url = "https://gitlab.com/login"
    sb.uc_open_with_reconnect(url, 4)
    sb.uc_gui_click_captcha()
    print(sb.get_page_title())

That script is working for me from GitHub Actions.

Code-With-Hashim commented 1 week ago

I run the same code on Linux that you gave me I'm attaching the image tell me what should I do next

image

mdmintz commented 1 week ago

Use sb.driver.title to get the the title instead. Then print it.

print(sb.driver.title)