Python Xvfb和Chrome Selenium驱动程序将大量信息打印到日志中,有时会崩溃

Python Xvfb和Chrome Selenium驱动程序将大量信息打印到日志中,有时会崩溃,python,python-3.x,selenium,xvfb,Python,Python 3.x,Selenium,Xvfb,我有一个python脚本,其中我使用了Chrome selenium驱动程序。有时它会崩溃,但我还没有找到原因。显然,这是由于Xvfb 以下是初始化驱动程序的方法: display = Display(visible=0, size=(800, 600)) display.start() chr_opt = webdriver.ChromeOptions() chr_opt.add_argument("--no-sandbox") chr_opt.add_argument("--user-ag

我有一个python脚本,其中我使用了Chrome selenium驱动程序。有时它会崩溃,但我还没有找到原因。显然,这是由于
Xvfb

以下是初始化驱动程序的方法:

display = Display(visible=0, size=(800, 600))
display.start()

chr_opt = webdriver.ChromeOptions()
chr_opt.add_argument("--no-sandbox")
chr_opt.add_argument("--user-agent={}".format(USER_AGENT))
drv = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=chr_opt)
以下是我的日志:

DEBUG:easyprocess:param: "['Xvfb', '-help']" 
DEBUG:easyprocess:command: ['Xvfb', '-help']
DEBUG:easyprocess:joined command: Xvfb -help
DEBUG:easyprocess:process was started (pid=19432)
DEBUG:easyprocess:process has ended
DEBUG:easyprocess:return code=0
DEBUG:easyprocess:stdout=
DEBUG:easyprocess:stderr=use: X [:<display>] [option]
-a #                   default pointer acceleration (factor)
-ac                    disable access control restrictions
-audit int             set audit trail level
-auth file             select authorization file

[.............................skipped ..............................]
[.............................skipped ..............................]

-whitepixel n          pixel value for white
-fbdir directory       put framebuffers in mmap'ed files in directory
-shmem                 put framebuffers in shared memory
DEBUG:easyprocess:param: "['xauth', '-h']" 
DEBUG:easyprocess:command: ['xauth', '-h']
DEBUG:easyprocess:joined command: xauth -h
DEBUG:easyprocess:process was started (pid=19433)
DEBUG:easyprocess:process has ended
DEBUG:easyprocess:return code=1  <------------------------ why? 1 means "error", doesn't?
DEBUG:easyprocess:stdout=
DEBUG:easyprocess:stderr=usage:  xauth [-options ...] [command arg ...]

where options include:
    -f authfilename                name of authority file to use
    -v                             turn on extra messages
    -q                             turn off extra messages
    -i                             ignore locks on authority file
    -b                             break locks on authority file
    -V                             show version number of xauth

and commands have the following syntax:

    add dpyname protoname hexkey   add entry
    exit                           save changes and exit program
    extract filename dpyname...    extract entries into file

    [.............................skipped ..............................]
    [.............................skipped ..............................]

    source filename                read commands from file
    version                        show version number of xauth
    ?                              list available commands
    generate dpyname protoname [options]  use server to generate entry
    options are:
      timeout n    authorization expiration time in seconds
      trusted      clients using this entry are trusted
      untrusted    clients using this entry are untrusted
      group n      clients using this entry belong to application group n
      data hexkey  auth protocol specific data needed to generate the entry


A dash may be used with the "merge" and "source" to read from the
standard input.  Commands beginning with "n" use numeric format.

DEBUG:easyprocess:param: "['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1054']" 
DEBUG:easyprocess:command: ['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1054']
DEBUG:easyprocess:joined command: Xvfb -br -nolisten tcp -screen 0 800x600x24 :1054
DEBUG:easyprocess:param: "['xauth', '-h']" 
DEBUG:easyprocess:command: ['xauth', '-h']
DEBUG:easyprocess:joined command: xauth -h
DEBUG:easyprocess:process was started (pid=19434)
DEBUG:easyprocess:process has ended
DEBUG:easyprocess:return code=1 <------------------------ why? 1 means "error", doesn't?
DEBUG:easyprocess:stdout=
DEBUG:easyprocess:stderr=usage:  xauth [-options ...] [command arg ...]

where options include:
    -f authfilename                name of authority file to use
    -v                             turn on extra messages
    -q                             turn off extra messages
    -i                             ignore locks on authority file
    -b                             break locks on authority file
    -V                             show version number of xauth

and commands have the following syntax:

    add dpyname protoname hexkey   add entry
    exit                           save changes and exit program
    extract filename dpyname...    extract entries into file
    help [topic]                   print help
    info                           print information about entries
    [.............................skipped ..............................]
    [.............................skipped ..............................]
    source filename                read commands from file
    version                        show version number of xauth
    ?                              list available commands
    generate dpyname protoname [options]  use server to generate entry
    options are:
      timeout n    authorization expiration time in seconds
      trusted      clients using this entry are trusted
      untrusted    clients using this entry are untrusted
      group n      clients using this entry belong to application group n
      data hexkey  auth protocol specific data needed to generate the entry


A dash may be used with the "merge" and "source" to read from the
standard input.  Commands beginning with "n" use numeric format.

DEBUG:easyprocess:param: "['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1055']" 
DEBUG:easyprocess:command: ['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1055']
DEBUG:easyprocess:joined command: Xvfb -br -nolisten tcp -screen 0 800x600x24 :1055
DEBUG:easyprocess:process was started (pid=19435)
DEBUG:pyvirtualdisplay.abstractdisplay:DISPLAY=:1055
DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:35260/session {"desiredCapabilities": {"platform": "ANY", "browserName": "chrome", "chromeOptions": {"extensions": [], "args": ["--no-sandbox", "--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"]}, "javascriptEnabled": true, "version": ""}, "requiredCapabilities": {}}
DEBUG:easyprocess:param:“['Xvfb','-help']”
调试:easyprocess:命令:['Xvfb','-help']
调试:easyprocess:joined命令:Xvfb-help
调试:easyprocess:进程已启动(pid=19432)
调试:easyprocess:进程已结束
调试:easyprocess:返回代码=0
调试:easyprocess:stdout=
调试:easyprocess:stderr=use:X[:][选项]
-a#默认指针加速度(系数)
-ac禁用访问控制限制
-audit int设置审核跟踪级别
-授权文件选择授权文件
[………..跳过………]
[………..跳过………]
-白色像素-白色的像素值
-fbdir目录将帧缓冲区放入目录中的mmap文件中
-shmem将帧缓冲区放入共享内存中
调试:easyprocess:param:“['xauth','-h']”
调试:easyprocess:命令:['xauth','-h']
调试:easyprocess:joined命令:xauth-h
调试:easyprocess:进程已启动(pid=19433)
调试:easyprocess:进程已结束
DEBUG:easyprocess:returncode=1
DEBUG:easyprocess:stderr=use:X[:][选项]

我必须处理它吗?如果是,如何处理?

此输出的原因: 在pyvirtualdisplay包中,下面的代码位于xauth.py文件中,用于检查是否安装了easyprocess

def is_installed():
    '''
    Return whether or not xauth is installed.
    '''
    try:
        easyprocess.EasyProcess(['xauth', '-h']).check_installed()
    except easyprocess.EasyProcessCheckInstalledError:
        return False
    else:
        return True
这里,-h由debug-in包使用,该包显示easyprocess的帮助选项,并在输出中显示相同的选项。因此,您的代码中不会出现任何问题

调试记录器中提供了帮助。因此,如果您想抑制这种情况,那么只需使用代码中的下一行将记录器设置为INFO level

logging.getLogger(“easyprocess”).setLevel(logging.INFO)

在初始化显示器之前输入上述代码(如下所述):

我希望它能解决你的问题

此输出的原因: 在pyvirtualdisplay包中,下面的代码位于xauth.py文件中,用于检查是否安装了easyprocess

def is_installed():
    '''
    Return whether or not xauth is installed.
    '''
    try:
        easyprocess.EasyProcess(['xauth', '-h']).check_installed()
    except easyprocess.EasyProcessCheckInstalledError:
        return False
    else:
        return True
这里,-h由debug-in包使用,该包显示easyprocess的帮助选项,并在输出中显示相同的选项。因此,您的代码中不会出现任何问题

调试记录器中提供了帮助。因此,如果您想抑制这种情况,那么只需使用代码中的下一行将记录器设置为INFO level

logging.getLogger(“easyprocess”).setLevel(logging.INFO)

在初始化显示器之前输入上述代码(如下所述):

我希望它能解决你的问题