解决chrome quit的问题

This commit is contained in:
liuwei
2025-05-26 10:35:49 +08:00
parent 2475fb8d7f
commit ec92d4218c

View File

@@ -44,6 +44,8 @@ def download_image(url):
def fetch_and_create_pdf(url): def fetch_and_create_pdf(url):
"""根据给定URL抓取页面并生成PDF""" """根据给定URL抓取页面并生成PDF"""
driver =None
try:
# 配置Selenium # 配置Selenium
options = Options() options = Options()
options.add_argument('--headless') # 使用新的headless模式 options.add_argument('--headless') # 使用新的headless模式
@@ -225,7 +227,13 @@ def fetch_and_create_pdf(url):
driver.quit() driver.quit()
# 如果生成失败,返回一个默认路径或空字符串 # 如果生成失败,返回一个默认路径或空字符串
return "" return ""
except Exception as e:
logger.info(f"抓取帖子时出错: {e}")
# 如果抓取失败,返回一个默认路径或空字符串
driver.quit()
return ""
finally:
driver.quit()
# add_pdf_encryption 和 pdf_file_path 函数保持不变 # add_pdf_encryption 和 pdf_file_path 函数保持不变
def add_pdf_encryption(pdf_file, password="4000"): def add_pdf_encryption(pdf_file, password="4000"):