59 lines
2.4 KiB
Python
59 lines
2.4 KiB
Python
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_argument('--user-data-dir=/home/pythagodzilla/.config/chromium/Default')
|
||
# 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(dr>iver) - None:
|
||
"""
|
||
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) # 等待页 面完全加载。
|