简体   繁体   English

消息:在Web服务器上执行python硒时,'chromedriver'可执行文件需要位于PATH中

[英]Message: 'chromedriver' executable needs to be in PATH while executing python selenium on web server

I have a python script for scraping with selenium. 我有一个用硒抓取的python脚本。 Everything is going well on my local laptop. 在我本地的笔记本电脑上一切都很好。 But when I put this python file on the web server, it always had errors about selenium and now I can't execute successfully owing to 但是,当我将此python文件放在Web服务器上时,它始终存在有关硒的错误,由于以下原因,我无法成功执行

Traceback (most recent call last):
  File "test_availability.py", line 32, in <module>
    driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=chrome_options)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: 
  Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

But I put the chromedriver in the same location as where chromedriver is on my local laptop on the web server. 但是,我将chromedriver放置在Web服务器上本地chromedriver器上chromedriver所在的位置。 And the error appears. 并出现错误。 I tried many methods but this error still there. 我尝试了许多方法,但此错误仍然存​​在。

I put chromedriver into /usr/local/bin on the web server My question is different from the selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome Since I already used the method from the accepted acswer, but there still show the error 我将chromedriver放入Web服务器上的/usr/local/bin ,我的问题与selenium.common.exceptions.WebDriverException不同:消息:“ Headless Chrome”的“ chromedriver”可执行文件需要出现PATH错误,因为我已经使用了接受的acswer,但仍然显示错误

I need to run my python file on the web server. 我需要在网络服务器上运行python文件。 Below is my codes: 以下是我的代码:

CHROMEDRIVER_PATH = "/home/animalsp/public_html/maps/maps2/chromedriver"
WINDOW_SIZE ="1920,1080"
chrome_options = Options() 
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)

driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=chrome_options)
driver.get("https://na.chargepoint.com/charge_point")

And I even tried it with Firefox. 我什至在Firefox上也尝试过。 Below is my codes with Firefox: 以下是我使用Firefox的代码:

FIREFOXDRIVER_PATH ="/home/animalsp/public_html/maps/maps2/geckodriver"
WINDOW_SIZE ="1920,1080"
firefox_options = Options() 
firefox_options.add_argument("--headless")
firefox_options.add_argument("--window-size=%s" % WINDOW_SIZE)

driver = webdriver.Firefox(executable_path=FIREFOXDRIVER_PATH, firefox_options=firefox_options)
driver.get("https://na.chargepoint.com/charge_point")

Could someone help me with this? 有人可以帮我吗? Any response will be appreciated! 任何回应将不胜感激!

Selenium 3.12.0 硒3.12.0

python 3.6.5 python 3.6.5

Chrome 66.0 铬66.0

Chromedriver 2.3.8 Chromedriver 2.3.8

Firefox 60 Firefox 60

geckodriver v0.20.1 壁虎驱动程序v0.20.1

You need to put your chromedriver executable file in same directory where you run your script and change your chrome_path to this: 您需要将chromedriver可执行文件放在运行脚本的目录中,并将chrome_path更改为以下目录:

import os
chrome_path = os.path.realpath('chromedriver')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium chromedriver 不适用于 php python - selenium chromedriver not work with php python Selenium ChromeDriver死于“驱动程序服务器已死。” - Selenium ChromeDriver Dies With “The driver server has died.” mac/php 的正确 Codeception(Selenium 服务器、chromedriver)故障排除程序是什么? - What are the correct Codeception (Selenium server, chromedriver) troubleshooting procedures for mac/php? 执行python脚本并从selenium导入webdriver时出现php脚本错误 - php script error while executing python script and importing webdriver from selenium Selenium测试在执行JavaScript时随机崩溃 - Selenium tests crash randomly while executing javascript Web服务器上的Spawn进程/运行可执行文件 - Spawn Process/Run Executable on Web Server 致命错误:找不到Facebook \\ WebDriver \\ Exception \\ UnknownServerException:等待驱动程序服务器从ChromeDriver和Selenium启动时超时 - Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownServerException: Timed out waiting for driver server to start with ChromeDriver and Selenium 在Web服务器中上传的文件路径 - file path for uploading in web server 执行脚本一段时间后,“无法连接到Selenium RC服务器” - “Could not connect to the Selenium RC server” after some time of executing script 从php执行python脚本时出错 - error while executing python script from php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM