3

我在我的蜘蛛(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

我读了这个,我尝试使用docker,我被困在这个阶段

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

我读了这个

如果您在运行 shub-image init 时遇到这样的 ImportError:您应该通过运行以下命令确保安装了最新版本的 shub:

$ 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
4

2 回答 2

3

你试过了吗:

sudo apt-get install xvfb

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

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

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

下载后,您可以将其 mv 到下载源的路径:

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

然后您更改目录并执行以下操作:

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

就这样!

于 2017-06-09T15:19:06.223 回答
1

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

1-对于我使用的docker中的xvfb

RUN apt-get install -qy xvfb

2- 用于创建docker映像,我使用了这个 并安装 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"]

这里

于 2017-06-14T10:05:45.063 回答