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

This commit is contained in:
liuwei
2025-03-27 16:55:00 +08:00
parent bc33426834
commit aa75d55d85

View File

@@ -85,7 +85,18 @@ def fetch_images(post_url):
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
# 使用本地固定的ChromeDriver路径避免每次自动更新
chrome_driver_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "chromedriver.exe")
# 如果本地没有chromedriver.exe则使用默认方式
if not os.path.exists(chrome_driver_path):
driver = webdriver.Chrome(options=options)
print("使用默认ChromeDriver")
else:
from selenium.webdriver.chrome.service import Service
driver = webdriver.Chrome(service=Service(chrome_driver_path), options=options)
print(f"使用本地ChromeDriver: {chrome_driver_path}")
for page in range(1, total_pages + 1):
url = f"{post_url}/{page}" if page > 1 else post_url