如何让selenium不弹出黑框

Pyinstaller打包时,希望隐藏driver控制台黑框的情况,解决方法如下:

1、

找到文件service.py(网上很多文章说是找services.py,但是我自己的selenium安装完只能有service.py,各位根据自己的情况看看是service.py还是services.py),具体路径为:C:\ProgramData\Anaconda3\Lib\site-packages\selenium\webdriver\common\service.py,

注意是common文件夹下的service.py

 2、

打开service.py文件,找到函数start,应该是在第61行的位置

    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.extend(self.command_line_args())
            self.process = subprocess.Popen(cmd, env=self.env,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self.log_file,
                                            stderr=self.log_file,
                                            stdin=PIPE)

3、

在stdin=PIPE后面加上一段代码creationflags=134217728,变成:

    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.extend(self.command_line_args())
            self.process = subprocess.Popen(cmd, env=self.env,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self.log_file,
                                            stderr=self.log_file,
                                            stdin=PIPE,
                                            creationflags=134217728)

这里注意一下,网上很多在creationflags=134217728后面加了逗号,导致出错,这里千万别多打一个逗号。

4、

保存文件,selenium不宰弹出黑框

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值