使用本地文件进行模拟浏览器,防止失败

This commit is contained in:
liuwei
2025-04-10 17:34:55 +08:00
parent f778890f69
commit 69fb2f89f3
3 changed files with 8 additions and 6 deletions

View File

@@ -50,8 +50,10 @@ def fetch_and_create_pdf(url):
options.add_argument('--no-sandbox')
# 使用本地固定的ChromeDriver路径避免每次自动更新
chrome_driver_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "chromedriver.exe")
chrome_driver_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"utils", "chromedriver", "chromedriver.exe"
)
# 如果本地没有chromedriver.exe则使用webdriver_manager下载一次
if not os.path.exists(chrome_driver_path):
chrome_driver_path = ChromeDriverManager().install()