From 86e245581a7b797ea7964e5ddd34ce449b3b8897 Mon Sep 17 00:00:00 2001
From: Pyhtagodzilla <1670671958@qq.com>
Date: Fri, 30 May 2025 08:41:46 +0800
Subject: [PATCH] For Edge, when you want use "--user-data-dir". Just go to
edge://version to check. "C:\Users\Plane\AppData\Local\Microsoft\Edge\User
Data\Profile 1". So when set options.addargument("--profile-directory=[]"),
It may not be the "Default".
---
.idea/.gitignore | 8 +++
.idea/BingPoints.iml | 8 +++
.idea/inspectionProfiles/Project_Default.xml | 10 ++++
.../inspectionProfiles/profiles_settings.xml | 6 +++
.idea/misc.xml | 7 +++
.idea/modules.xml | 8 +++
.idea/vcs.xml | 6 +++
run.py | 22 ++++++++
utils.py | 53 +++++++++++++++++++
9 files changed, 128 insertions(+)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/BingPoints.iml
create mode 100644 .idea/inspectionProfiles/Project_Default.xml
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 run.py
create mode 100644 utils.py
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/BingPoints.iml b/.idea/BingPoints.iml
new file mode 100644
index 0000000..2140ac9
--- /dev/null
+++ b/.idea/BingPoints.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..efae37f
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..18905db
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..744af8a
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/run.py b/run.py
new file mode 100644
index 0000000..19685f7
--- /dev/null
+++ b/run.py
@@ -0,0 +1,22 @@
+from utils import init_driver_edge
+from selenium.webdriver.common.by import By
+import time
+
+def test() -> None:
+ driver = init_driver_edge()
+ driver.get("http://baidu.com")
+
+def do_check_in():
+ driver = init_driver_edge()
+ time.sleep(10)
+ 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")
+ for i in cont:
+ if i.get_attribute('role') == 'banner' or i.get_attribute('id') == 'exclusive_promo_cont':
+ i.click()
+
+ time.sleep(10)
+
+if __name__ == "__main__":
+ do_check_in()
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..1911580
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,53 @@
+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
+
+# from selenium import webdriver
+# from selenium.webdriver.edge.service import Service
+# from time import sleep
+#
+# ser = Service("E:\\webdriver\\msedgedriver.exe")
+# edge_options = webdriver.EdgeOptions()
+# edge_options.use_chromium = True
+# edge_options.add_argument("user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\Edge\\User Data")
+# edge_options.add_argument("profile-directory=Profile 1")
+#
+# driver = webdriver.Edge(service = ser,options = edge_options)
+# driver.get('https://www.bing.com')
+#
+# sleep(20)
\ No newline at end of file