Python+selenium+pyinstaller 消除cmd窗口

问题描述:

Python+selenium程序经过pyinstaller打包成exe文件后,启动exe文件后,会打开一个XXXdriver.exe的cmd窗口,直接关闭cmd窗口会导致程序打开的浏览器被关闭。

目的:

保持浏览器打开,并且关闭cmd窗口。

解决方法:

1.修改service.py文件

文件位置:

......Python\Python38\Lib\site-packages\selenium\webdriver\common\service.py

修改内容
1.引入库
import sys
 2.start函数替换(实际上只修改了try块中的内容)
def start(self):
        """
        Starts the Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        try:
            cmd = [self.path]
            cmd.e
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值