mac/win使用pyinstaller打包app/exe文件,活着执行脚本,双击运行-???? 源码

时间:2024-04-10 20:09:58
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驱动程序
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