from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import os

# 自动获取桌面路径（环境变量，不用手动写）
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")

# 1. 自动拼接 Chrome 浏览器路径
chrome_exe_path = os.path.join(desktop_path, "chrome-win64", "chrome-win64", "chrome.exe")
chrome_options = Options()
chrome_options.binary_location = chrome_exe_path

# 2. 自动拼接 chromedriver 路径
driver_path = os.path.join(desktop_path, "chromedriver-win64", "chromedriver-win64", "chromedriver.exe")
service = Service(driver_path)

# 3. 启动浏览器
driver = webdriver.Chrome(service=service, options=chrome_options)

# 测试
driver.get("https://www.baidu.com")
print("打开成功！")