优化插件,不用每次都远程下载

This commit is contained in:
liuwei
2025-03-27 16:42:33 +08:00
parent b8dfd3cf72
commit bc33426834

View File

@@ -48,7 +48,18 @@ def fetch_and_create_pdf(url):
options.headless = True
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
# 使用本地固定的ChromeDriver路径避免每次自动更新
chrome_driver_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "chromedriver.exe")
# 如果本地没有chromedriver.exe则使用webdriver_manager下载一次
if not os.path.exists(chrome_driver_path):
chrome_driver_path = ChromeDriverManager().install()
print(f"ChromeDriver已下载到: {chrome_driver_path}")
else:
print(f"使用本地ChromeDriver: {chrome_driver_path}")
driver = webdriver.Chrome(service=Service(chrome_driver_path), options=options)
# 获取目标页面
driver.get(url)