Home>

I want to run selenium on Pytho with cron on CentOS8,
I get an error with chromedriver.
When I type and execute the command on CentoOS, it works.
It doesn't work with cron. . .

I checked variously on the net, but it seems that the path is the cause,
Since it is set as follows, I do not know where the path is wrong. . .
options = Options ()
options.add_argument ('-headless')
options.add_argument ('-no-sandbox')
options.add_argument ('-disable-gpu')
options.add_argument ('-window-size = 1280,1024')
driver = webdriver.Chrome (chrome_options = options)

I hope you will teach me.

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin = PIPE)
  File "/usr/lib64/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib64/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type (errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/takahiro/py/Test.py", line 38, in<module>
    driver = webdriver.Chrome (chrome_options = options)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, 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
Applicable source code
#!/usr/bin/env python
import random
import psycopg2
import tempfile
from selenium import webdriver
from bs4 import BeautifulSoup
import requests
import time
import cv2
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.options import Options
from requests.exceptions import Timeout

# web driver
options = Options ()
options.add_argument ('-headless')
options.add_argument ('-no-sandbox')
options.add_argument ('-disable-gpu')
options.add_argument ('-window-size = 1280,1024')
driver = webdriver.Chrome (chrome_options = options)
Supplemental information (FW/tool version, etc.)

Python3.6
CentOS8

  • Answer # 1

    PATH may be the cause, so on the command lineecho $PATHAnd the resultcrontabLet's write before the execution specification of.
    For example,

    echo $PATH
    →/home/xxxx/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin


    in the case of,

    PATH =/home/xxxx/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
    0 1 * * * python/home/xxxx/yyyyyyyyy


    Like