feat: automates ChromeDriver management

Updates the ChromeDriver setup to use `webdriver_manager` instead of relying on a local executable. This ensures the correct ChromeDriver version is automatically downloaded and managed, improving reliability and reducing manual configuration.

Removes the now unnecessary `chromedriver.exe` from the `.gitignore` file.
This commit is contained in:
kinoshitakenta 2025-05-19 11:02:58 +08:00
parent f66cf7aeac
commit 0b80ee79b1
Signed by: kinoshitakenta
GPG Key ID: A811E8CA36EF425E
2 changed files with 2 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,9 +1,6 @@
# module cache
__pycache__/
# selenium driver
chromedriver.exe
# log file
*.log

View File

@ -1,16 +1,15 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.webdriver import WebDriver
from webdriver_manager.chrome import ChromeDriverManager
def get_driver() -> WebDriver:
service = Service(executable_path='./chromedriver.exe')
options = webdriver.ChromeOptions()
# options.add_argument("--headless")
options.add_argument('--disable-gpu')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(service=service, options=options)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.implicitly_wait(4)
return driver