BingPoints/utils.py
2025-05-30 08:58:40 +08:00

53 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from selenium import webdriver
def init_driver_edge():
"""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.edge.options import Options
service = Service(r"D:\Projects\BUCT\edgedriver\msedgedriver.exe")
edge_options = Options()
# edge_options.add_argument("--headless") # Run in headless mode
edge_options.add_argument("--no-sandbox")
edge_options.add_experimental_option("detach", False)
edge_options.add_argument("--user-data-dir=C:\\Users\\Plane\\AppData\\Local\\Microsoft\\Edge\\User Data")
# edge_options.add_argument(r"user-data-dir=")
edge_options.add_argument("--profile-directory=Profile 1")
driver = webdriver.Edge(options=edge_options, service=service)
driver.implicitly_wait(5) # Implicit wait for elements to load
return driver
def init_driver_chrome():
"""Initialize the Selenium WebDriver with Chrome options.
Returns:
WebDriver: The initialized Selenium WebDriver instance.
"""
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
service = Service(executable_path="/usr/bin/chromedriver")
options = Options()
options.add_argument("--headless") # Run in headless mode
options.add_argument("--no-sandbox")
# options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=options)
driver.implicitly_wait(5) # Implicit wait for elements to load
return driver
def get_points(driver) -> None:
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") # 查找classpromo_cont。但对应多个可点击元素
for i in cont:
if i.get_attribute('role') == 'banner' or i.get_attribute('id') == 'exclusive_promo_cont':
i.click() # 点击所有符合元素
time.sleep(10) # 等待页面完全加载。