我在我的蜘蛛(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
我读了这个
如果在运行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
答案 0 :(得分:3)
sudo apt-get install xvfb
另一种方法是手动编译包,一种:
apt-get source xvfb
./configure --prefix=$HOME/myapps
make
make install
第三种方法是从源网页https://pkgs.org/download/xvfb
下载.deb下载后,您可以将其转到下载源的路径:
mv xvfb_1.16.4-1_amd64.deb /var/cache/apt/archives/
然后你改变目录并执行:
sudo dpkg -i xvfb_1.16.4-1_amd64.deb
就是这样!
答案 1 :(得分:1)
我解决了我的问题(在scrapinghub中使用selenium )
1 - for docker中的 xvfb 我使用
RUN apt-get install -qy xvfb
用于创建泊坞窗图片的2 - 我使用了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