import os
import sys
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
"""
常用参数 含义
-i 或 -icon 生成icon
-F 创建一个绑定的可执行文件
-w 使用窗口,无控制台
-C 使用控制台,无窗口
-D 创建一个包含可执行文件的单文件夹包(默认情况下)
-n 文件名
mac pyinstaller -F -w -i favicon.ico trustCertificates.py
win pyinstaller -F --onefile -i favicon.ico trustCertificates.py
"""
chrome_options = Options()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
chrome_driver_path = 'path_to_chromedriver'
service = Service(chrome_driver_path)
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
path = os.path.dirname(sys.argv[0])
f = os.path.join(path, 'url.txt')
websites = open(f).readlines()
for website in websites[1:]:
try:
driver.get(website)
WebDriverWait(driver, 3).until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
print(f"成功信任证书: {website}")
except Exception as e:
raise e
print(f"无法信任证书: {website}, 错误信息: {str(e)}")
driver.get(websites[0])
while True:
pass