環境
- Conoha VPS
- CentOS Apache2.0
- Python 3.75
- Google Chrome 83.0.4103.116
- ChromeDriver 83.0.4103.39
- selenium Version: 3.141.0
ディレクトリ
/var/www/cgi-bin/test.py 755
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_binary
import cgi # CGIモジュールのインポート
import cgitb
cgitb.enable()
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
#driver = webdriver.Chrome('/usr/local/bin/chromedriver')
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',options=options)
print("Content-Type: text/plain;charset=utf-8") #HTMLを出力するために必要
print("") #HTMLを出力するために必要
driver.get('https://yahoo.co.jp')
print(driver.title)
/var/www/cgi-bin上で
python test.py
を実行すると
Content-Type: text/plain;charset=utf-8
Yahoo! JAPAN
と結果が返ってきます。
しかし、
xxx.xx.xx(IPアドレス)/cgi-bin/test.py
をWEB上で開くと500エラーになります。
エラーのログを確認すると
no module named selenium python
と出てきます。
seleniumはすでに入っているはずで、以下の結果も確認済みです。
pip install selenium
Requirement already satisfied: selenium in /root/.pyenv/versions/3.7.5/lib/python3.7/site-packages (3.141.0)
Requirement already satisfied: urllib3 in /root/.pyenv/versions/3.7.5/lib/python3.7/site-packages (from selenium) (1.25.9)
pip3 show webdriver
を実行すると
WARNING: Package(s) not found: webdriver
のエラーが出てきます。
また、以前別のサーバー(IPアドレス)で同様の環境で、WEB上で「Yahoo! JAPAN」と出力することに成功しています。
そのサーバーでは
pip3 show webdriver
を実行するとなにも出力されません。
何か足りないものはあるでしょうか?
たくさんのサイトを見て何時間も挑戦しましたが、私には解決できませんでした。
お力添えいただけると幸いです。
他に必要な情報があればお知らせください。
どうぞよろしくお願いいたします。