测试
This commit is contained in:
parent
21783d06af
commit
214a8c6c74
21
run.py
21
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:
|
||||||
|
driver = Bing.init_driver_edge(path)
|
||||||
|
Bing.get_points(driver=driver)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
get_points(driver=driver)
|
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/")
|
19
utils.py
19
utils.py
@ -1,6 +1,10 @@
|
|||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
|
|
||||||
def init_driver_edge():
|
|
||||||
|
class Bing:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def init_driver_edge(profile_path: str):
|
||||||
"""Initialize the Selenium WebDriver with Edge edge_options.
|
"""Initialize the Selenium WebDriver with Edge edge_options.
|
||||||
Returns:
|
Returns:
|
||||||
WebDriver: The initialized Selenium WebDriver instance.
|
WebDriver: The initialized Selenium WebDriver instance.
|
||||||
@ -12,14 +16,16 @@ def init_driver_edge():
|
|||||||
# edge_options.add_argument("--headless") # Run in headless mode
|
# edge_options.add_argument("--headless") # Run in headless mode
|
||||||
edge_options.add_argument("--no-sandbox")
|
edge_options.add_argument("--no-sandbox")
|
||||||
edge_options.add_experimental_option("detach", False)
|
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(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(r"user-data-dir=")
|
||||||
edge_options.add_argument("--profile-directory=Profile 1")
|
edge_options.add_argument("--profile-directory=Profile 1")
|
||||||
driver = webdriver.Edge(options=edge_options, service=service)
|
driver = webdriver.Edge(options=edge_options, service=service)
|
||||||
driver.implicitly_wait(5) # Implicit wait for elements to load
|
driver.implicitly_wait(5) # Implicit wait for elements to load
|
||||||
return driver
|
return driver
|
||||||
|
|
||||||
def init_driver_chrome():
|
@staticmethod
|
||||||
|
def init_driver_chrome(profile_path: str):
|
||||||
"""Initialize the Selenium WebDriver with Chrome options.
|
"""Initialize the Selenium WebDriver with Chrome options.
|
||||||
Returns:
|
Returns:
|
||||||
WebDriver: The initialized Selenium WebDriver instance.
|
WebDriver: The initialized Selenium WebDriver instance.
|
||||||
@ -31,13 +37,15 @@ def init_driver_chrome():
|
|||||||
options = Options()
|
options = Options()
|
||||||
options.add_argument("--headless") # Run in headless mode
|
options.add_argument("--headless") # Run in headless mode
|
||||||
options.add_argument("--no-sandbox")
|
options.add_argument("--no-sandbox")
|
||||||
options.add_argument('--user-data-dir=/home/pythagodzilla/.config/chromium')
|
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)
|
# options.add_experimental_option("detach", True)
|
||||||
driver = webdriver.Chrome(service=service, options=options)
|
driver = webdriver.Chrome(service=service, options=options)
|
||||||
driver.implicitly_wait(5) # Implicit wait for elements to load
|
driver.implicitly_wait(5) # Implicit wait for elements to load
|
||||||
return driver
|
return driver
|
||||||
|
|
||||||
def get_points(driver) -> None:
|
@staticmethod
|
||||||
|
def get_points(driver):
|
||||||
"""
|
"""
|
||||||
Open the rewards page and click all add-points elements.
|
Open the rewards page and click all add-points elements.
|
||||||
"""
|
"""
|
||||||
@ -54,5 +62,4 @@ def get_points(driver) -> None:
|
|||||||
if i.get_attribute('role') == 'banner' or i.get_attribute('id') == 'exclusive_promo_cont':
|
if i.get_attribute('role') == 'banner' or i.get_attribute('id') == 'exclusive_promo_cont':
|
||||||
i.click() # 点击所有符合元素
|
i.click() # 点击所有符合元素
|
||||||
|
|
||||||
|
|
||||||
time.sleep(10) # 等待页 面完全加载。
|
time.sleep(10) # 等待页 面完全加载。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user