优化插件,不用每次都远程下载
This commit is contained in:
@@ -85,7 +85,18 @@ def fetch_images(post_url):
|
|||||||
|
|
||||||
options = Options()
|
options = Options()
|
||||||
options.headless = True
|
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):
|
for page in range(1, total_pages + 1):
|
||||||
url = f"{post_url}/{page}" if page > 1 else post_url
|
url = f"{post_url}/{page}" if page > 1 else post_url
|
||||||
|
|||||||
Reference in New Issue
Block a user