From 17791aaadc2784381445a95f8e76435c03512e03 Mon Sep 17 00:00:00 2001 From: Pythagodzilla Date: Mon, 19 Jan 2026 23:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=89=A7=E8=A1=8C=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E6=90=AC=E8=BF=81=E8=87=B3docker=E4=B8=AD=EF=BC=8C=E5=85=B6?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E7=94=B1=E4=BA=8E=E5=A4=9A=E5=BC=80=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=9C=A8=E6=9F=90=E7=A7=8D=E7=A8=8B=E5=BA=A6=E4=B8=8A?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E7=9A=84=E8=B5=84=E6=BA=90=E7=B4=A7?= =?UTF-8?q?=E5=BC=A0=EF=BC=8C=E9=9C=80=E8=A6=81=E8=AE=BE=E7=BD=AE=20disabl?= =?UTF-8?q?e-dev-shm-usage.=20=E5=B9=B6=E4=B8=94=E5=9C=A8=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=AE=B9=E5=99=A8=E6=97=B6=E5=8A=A0=E5=A4=A7shm:=20--?= =?UTF-8?q?shm-size=3D2g=20=E6=9D=A5=E9=98=B2=E6=AD=A2=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E7=B4=A7=E5=BC=A0=E5=AF=BC=E8=87=B4=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=92=8C=E9=80=80=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/BingPoints.iml | 2 +- .idea/misc.xml | 2 +- run.py | 22 ++++++++++------------ utils.py | 38 +++++++++----------------------------- 4 files changed, 21 insertions(+), 43 deletions(-) diff --git a/.idea/BingPoints.iml b/.idea/BingPoints.iml index 2140ac9..f571432 100644 --- a/.idea/BingPoints.iml +++ b/.idea/BingPoints.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 18905db..59e780e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/run.py b/run.py index 6ca088b..623626c 100644 --- a/run.py +++ b/run.py @@ -3,21 +3,19 @@ import selenium.common from utils import Bing User_profile_chrome = ["chromium"] -User_profile_edge = ["User Data","User DataBM"] def main(): - for path in User_profile_edge: - try: - driver = Bing.init_driver_edge(path) - Bing.get_points(driver=driver) - time.sleep(10) - Bing.get_points(driver=driver) - time.sleep(10) - driver.quit() - print("quit") + try: + driver = Bing.init_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) + except selenium.common.exceptions.WebDriverException as e: + print(e) if __name__ == "__main__": diff --git a/utils.py b/utils.py index 5dc0bf3..14dcc23 100644 --- a/utils.py +++ b/utils.py @@ -4,43 +4,23 @@ from selenium import webdriver class Bing: @staticmethod - def init_driver_edge(profile_path: str): + 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.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(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 - - @staticmethod - def init_driver_chrome(profile_path: str): - """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("--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) + 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