from selenium import webdriver class Bing: @staticmethod def init_driver(): """Initialize the Selenium WebDriver with Edge edge_options. Returns: WebDriver: The initialized Selenium WebDriver instance. """ from selenium.webdriver.edge.service import Service from selenium.webdriver.chrome.options import Options options = Options() # options.add_argument("--headless") # Run in headless mode options.add_argument("--no-sandbox") options.add_experimental_option("detach", True) options.add_argument("--disable-dev-shm-usage") options.add_argument(f"--user-data-dir=/tmp/chrome-profile") # options.add_argument(f"--user-data-dir=C:\\Users\\Plane\\AppData\\Local\\Microsoft\\Edge\\{profile_path}") # options.add_argument(f"--user-data-dir=C:\\Users\\Plane\\AppData\\Local\\Microsoft\\Edge\\User Data") options.add_argument("--profile-directory=Default") # Use Default profile driver = webdriver.Remote(command_executor="http://localhost:9002/wd/hub", options=options) driver.implicitly_wait(5) # Implicit wait for elements to load return driver @staticmethod def get_points(driver): """ Open the rewards page and click all add-points elements. """ import time from selenium.webdriver.common.by import By driver.get( "https://cn.bing.com/rewards/panelflyout?channel=bingflyout&partnerId=BingRewards&isDarkMode=0&ru=https%3A%2F%2Fcn.bing.com%2F") driver.maximize_window() cont = driver.find_elements(By.CLASS_NAME, "promo_cont") # 查找class:promo_cont。但对应多个可点击元素 for i in cont: if i.get_attribute('role') == 'banner' or i.get_attribute('id') == 'exclusive_promo_cont': i.click() # 点击所有符合元素 time.sleep(10) # 等待页 面完全加载。