测试
This commit is contained in:
parent
21783d06af
commit
214a8c6c74
23
run.py
23
run.py
@ -1,13 +1,24 @@
|
|||||||
import time
|
import time
|
||||||
|
import selenium.common
|
||||||
|
from utils import Bing
|
||||||
|
|
||||||
from utils import init_driver_edge, init_driver_chrome
|
User_profile_chrome = ["chromium"]
|
||||||
from utils import get_points
|
User_profile_edge = ["User Data","User DataBM"]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
driver = init_driver_chrome()
|
for path in User_profile_edge:
|
||||||
get_points(driver=driver)
|
try:
|
||||||
time.sleep(10)
|
driver = Bing.init_driver_edge(path)
|
||||||
get_points(driver=driver)
|
Bing.get_points(driver=driver)
|
||||||
|
time.sleep(10)
|
||||||
|
Bing.get_points(driver=driver)
|
||||||
|
time.sleep(10)
|
||||||
|
driver.quit()
|
||||||
|
print("quit")
|
||||||
|
|
||||||
|
except selenium.common.exceptions.WebDriverException as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
4
test_profile.py
Normal file
4
test_profile.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from utils import Bing
|
||||||
|
|
||||||
|
driver = Bing.init_driver_edge("User DataXL")
|
||||||
|
driver.get("https://www.bing.com/")
|
103
utils.py
103
utils.py
@ -1,58 +1,65 @@
|
|||||||
from selenium import webdriver
|
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():
|
class Bing:
|
||||||
"""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")
|
@staticmethod
|
||||||
options = Options()
|
def init_driver_edge(profile_path: str):
|
||||||
options.add_argument("--headless") # Run in headless mode
|
"""Initialize the Selenium WebDriver with Edge edge_options.
|
||||||
options.add_argument("--no-sandbox")
|
Returns:
|
||||||
options.add_argument('--user-data-dir=/home/pythagodzilla/.config/chromium')
|
WebDriver: The initialized Selenium WebDriver instance.
|
||||||
# options.add_experimental_option("detach", True)
|
"""
|
||||||
driver = webdriver.Chrome(service=service, options=options)
|
from selenium.webdriver.edge.service import Service
|
||||||
driver.implicitly_wait(5) # Implicit wait for elements to load
|
from selenium.webdriver.edge.options import Options
|
||||||
return driver
|
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(f"--user-data-dir=C:\\Users\\Plane\\AppData\\Local\\Microsoft\\Edge\\{profile_path}")
|
||||||
|
# edge_options.add_argument(f"--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 get_points(driver) -> None:
|
@staticmethod
|
||||||
"""
|
def init_driver_chrome(profile_path: str):
|
||||||
Open the rewards page and click all add-points elements.
|
"""Initialize the Selenium WebDriver with Chrome options.
|
||||||
"""
|
Returns:
|
||||||
import time
|
WebDriver: The initialized Selenium WebDriver instance.
|
||||||
from selenium.webdriver.common.by import By
|
"""
|
||||||
driver.get(
|
from selenium.webdriver.chrome.options import Options
|
||||||
"https://cn.bing.com/rewards/panelflyout?channel=bingflyout&partnerId=BingRewards&isDarkMode=0&ru=https%3A%2F%2Fcn.bing.com%2F")
|
from selenium.webdriver.chrome.service import Service
|
||||||
|
|
||||||
driver.maximize_window()
|
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(f'--user-data-dir=/home/pythagodzilla/.config/{profile_path}')
|
||||||
|
# options.add_argument('--user-data-dir=/home/pythagodzilla/.config/chromium')
|
||||||
|
# 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
|
||||||
|
|
||||||
cont = driver.find_elements(By.CLASS_NAME, "promo_cont") # 查找class:promo_cont。但对应多个可点击元素
|
@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")
|
||||||
|
|
||||||
for i in cont:
|
driver.maximize_window()
|
||||||
if i.get_attribute('role') == 'banner' or i.get_attribute('id') == 'exclusive_promo_cont':
|
|
||||||
i.click() # 点击所有符合元素
|
|
||||||
|
|
||||||
|
cont = driver.find_elements(By.CLASS_NAME, "promo_cont") # 查找class:promo_cont。但对应多个可点击元素
|
||||||
|
|
||||||
time.sleep(10) # 等待页 面完全加载。
|
for i in cont:
|
||||||
|
if i.get_attribute('role') == 'banner' or i.get_attribute('id') == 'exclusive_promo_cont':
|
||||||
|
i.click() # 点击所有符合元素
|
||||||
|
|
||||||
|
time.sleep(10) # 等待页 面完全加载。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user