[英]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.