3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

cronでselenium実行できない?

Last updated at Posted at 2021-08-28

cronでselenium実行したい

・・・動かない?

手動では実行できるのに、cronではエラーで実行されず。

$ sudo /etc/init.d/cron status

errorsample.png

こんな感じでエラーがでた。

解決策

原因はここに書いてある内容だった。
環境変数DISPLAYが無いので、ブラウザ画面を表示できないでブラウザが起動できない、という事らしい。

cronを編集

$ crontab -e

cronのコマンド前に、DISPLAY=:0.0を追加。
これで解決した。

cronsample.png

ブラウザ表示が不要ならchrome driverのoptionを--headlessモードにすればよいらしい。

CHROME_BIN = "/usr/bin/chromium-browser"
CHROME_DRIVER = '/usr/lib/chromium-browser/chromedriver'
 
options = Options()
options.binary_location = CHROME_BIN
options.add_argument('--headless')
 
driver = webdriver.Chrome(CHROME_DRIVER, options=options)
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?