Ubuntu 16.04 pyvirtualdisplay值

2022-01-19 01:20:47 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试启动pyvirtualdisplay时出现以下错误:

>>> from pyvirtualdisplay import Display
>>> display = Display(visible=0, size=(1024, 768)).start()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pyvirtualdisplay/display.py", line 38, in __init__
    **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/pyvirtualdisplay/xvfb.py", line 33, in __init__
    AbstractDisplay.__init__(self)
  File "/usr/local/lib/python3.6/dist-packages/pyvirtualdisplay/abstractdisplay.py", line 33, in __init__
    self.display = self.search_for_display()
  File "/usr/local/lib/python3.6/dist-packages/pyvirtualdisplay/abstractdisplay.py", line 66, in search_for_display
    ls = [int(x.split('X')[1].split('-')[0]) for x in self.lock_files()]
  File "/usr/local/lib/python3.6/dist-packages/pyvirtualdisplay/abstractdisplay.py", line 66, in <listcomp>
    ls = [int(x.split('X')[1].split('-')[0]) for x in self.lock_files()]
ValueError: invalid literal for int() with base 10: 'O'

我安装了Xvfb:

apt-get install xvfb

我不明白为什么会这样。我使用的是Python3.6,ubuntu16.04。我需要用Selenium运行一些Scrapy脚本,--headless模式不合适,所以这似乎是唯一的选择:

display = Display(visible=0, size=(800, 800))
display.start()
driver = webdriver.Chrome()
driver.get('https://google.com')

有没有其他的建议或帮助呢?你知道吗