python - 可执行文件在路径中,但 selenium 在 docker frolvlad/alpine-python3 中找不到
问题描述
我正在尝试在高山码头运行 selenium。我已经管理了它,FROM python:3
但是节省磁盘空间会很好。
我收到错误消息
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
,FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
谷歌搜索只会给出“将 geckodriver 放入您的 $PATH”和“使用 PATH=$PATH:/usr/src/app 将 geckodriver 的文件夹路径添加到 $PATH”
但是geckodriver
在 $PATH 中,它仍然会导致相同的错误。
我还尝试将可执行文件作为参数添加到,driver = webdriver.Firefox()
但它没有任何改变。
WebDriverException:'geckodriver' 可执行文件需要在 PATH 中,即使它是(1 个答案)
selenium.common.exceptions.WebDriverException:消息:'geckodriver' 可执行文件需要在 PATH 中与 GeckoDriver Selenium Firefox(2 个答案)
Python 3.5 - “ Geckodriver 可执行文件需要在 PATH 中”(4 个答案)
Dockerfile:
FROM frolvlad/alpine-python3
WORKDIR /usr/src/app
COPY . .
RUN tar -xzf geckodriver-v0.26.tar.gz && cp geckodriver /bin
RUN pip install --no-cache-dir -r requirements.txt
RUN apk add --no-cache firefox-esr xvfb
ENV DISPLAY=:1.0
ENTRYPOINT ["./entrypoint.sh"]
入口点.sh
Xvfb :1 -screen 0 1024x768x16 &> xvfb.log &
python ./seleniumTest.py
输出:
/usr/src/app # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/src/app:/usr/src/app
/usr/src/app # which geckodriver
/bin/geckodriver
/usr/src/app # type geckodriver
geckodriver is /bin/geckodriver
/usr/src/app # ls -l /bin/geckodriver
-rwxr-xr-x 1 root root 7008696 Mar 3 18:29 /bin/geckodriver
/usr/src/app # ./entrypoint.sh
xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./seleniumTest.py", line 8, in <module>
driver= webdriver.Firefox()
File "/usr/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/usr/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
硒测试.py:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
url = 'https://stackoverflow.com/questions/15018372/how-to-take-partial-screenshot-with-selenium-webdriver-in-python'
driver= webdriver.Firefox()
driver.get(url)
element = driver.find_element_by_css_selector('#question-header')
image = element.screenshot('screenshot.png')
解决方案
推荐阅读
- apache-kafka - 在并行处理消息的同时处理 kafka 偏移
- python - 无法使用 python 从 Kibana 读取聚合数据
- python - python - 如何在python中使用带有Path变量的svg.path绘制椭圆?
- python - 尝试在 Spyder 上安装 fastai,但不知道如何解决此错误
- java - 如何在 Junit 中模拟查询类?
- python - Discord.py 检查参数是否是某些值之间的数字
- sql-server - PRIMARY 文件组已满
- checkbox - Highcharts - 图例复选框状态未更改
- powershell - powershell 结合 where 和 or
- php - Ajax 没有在 wordpress 前面醒来