BingPoints/utils.py
Pythagodzilla 17791aaadc 将执行环境搬迁至docker中,其中,由于多开页面在某种程度上会导致的资源紧张,需要设置
disable-dev-shm-usage.
并且在创建容器时加大shm:
--shm-size=2g
来防止资源紧张导致的错误和退出。
2026-01-19 23:59:17 +08:00

46 lines
1.9 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
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") # 查找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) # 等待页 面完全加载。