如何在 Scrapinghub 上安装 xvfb 以使用 Selenium?

How to install xvfb on Scrapinghub for using Selenium?

我在我的蜘蛛(Scrapy)中使用 Python-Selenium,为了使用 Selenium,我应该在 Scrapinghub 上安装 xvfb .

当我使用 apt-get 安装 xvfb 时出现此错误消息:

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)                                                                                                                                                                
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

有没有其他方法可以在 Scrapinghub 上安装 xvfb

更新 1

我阅读了this,我尝试使用docker,我卡在了这个阶段

shub-image init --requirements path/to/requirements.txt

我读了这个

If you are getting an ImportError like this while running shub-image init: You should make sure you have the latest version of shub installed by running:

$ pip install shub --upgrade

但我总是遇到这个错误

Traceback (most recent call last):
  File "/usr/local/bin/shub-image", line 7, in <module>
    from shub_image.tool import cli
  File "/usr/local/lib/python2.7/dist-packages/shub_image/tool.py", line 42, in <module>
    command_module = importlib.import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/shub_image/push.py", line 4, in <module>
    from shub.deploy import list_targets
ImportError: cannot import name list_targets

你试过了吗:

sudo apt-get install xvfb

另一种方法是手动编译包,一种:

apt-get source xvfb
./configure --prefix=$HOME/myapps
make
make install

第三种方式是从源网页下载.deb https://pkgs.org/download/xvfb

下载后,mv到下载源路径:

mv xvfb_1.16.4-1_amd64.deb /var/cache/apt/archives/

然后您更改目录并执行:

sudo dpkg -i xvfb_1.16.4-1_amd64.deb

仅此而已!

我解决了我的问题(在 scrapinghub 中使用 selenium

1- 对于 xvfb 在 docker 我使用

RUN apt-get install -qy xvfb

2- 用于创建 docker 图像 我使用了 this 为了安装 geckodriver,我使用了这段代码

#
# Geckodriver Dockerfile
#

FROM blueimp/basedriver

# Add the Firefox release channel of the Debian Mozilla team:
RUN echo 'deb http://mozilla.debian.net/ jessie-backports firefox-release' >> \
  /etc/apt/sources.list \
  && curl -sL https://mozilla.debian.net/archive.asc | apt-key add -

# Install Firefox:
RUN export DEBIAN_FRONTEND=noninteractive \
  && apt-get update \
  && apt-get install --no-install-recommends --no-install-suggests -y \
    firefox \
  # Remove obsolete files:
  && apt-get clean \
  && rm -rf \
    /tmp/* \
    /usr/share/doc/* \
    /var/cache/* \
    /var/lib/apt/lists/* \
    /var/tmp/*

# Install geckodriver:
RUN export BASE_URL=https://github.com/mozilla/geckodriver/releases/download \
  && export VERSION=$(curl -sL \
    https://api.github.com/repos/mozilla/geckodriver/releases/latest | \
    grep tag_name | cut -d '"' -f 4) \
  && curl -sL \
  $BASE_URL/$VERSION/geckodriver-$VERSION-linux64.tar.gz | tar -xz \
  && mv geckodriver /usr/local/bin/geckodriver

USER webdriver

CMD ["geckodriver", "--host", "0.0.0.0"]

来自 here