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

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

2
.gitignore vendored
View File

@@ -8,5 +8,3 @@ __pycache__
logs/
*.log
*.log.*
config.yaml

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()

View File

@@ -87,8 +87,10 @@ def fetch_images(post_url):
options.headless = True
# 使用本地固定的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则使用默认方式
if not os.path.exists(chrome_driver_path):
driver = webdriver.Chrome(options=options)