我正在尝试在heroku上设置硒和chromedriver。堆栈是heroku-16 但是在安装过程中遇到了以下问题。 如何在buildpack中设置chromedriver的路径?
$ Heroku buildpacks
1. heroku/python
2. https://github.com/heroku/heroku-buildpack-chromedriver
3. https://github.com/notvad/heroku-buildpack-selenium.git
4. https://github.com/heroku/heroku-buildpack-chromedriver.git
参数
CHROMEDRIVER_PATH = "/app/.chromedriver/bin/chromedriver"
GOOGLE_CHROME_BIN = "/app/.apt/usr/bin/google-chrome
代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options as ChromeOptions
from bs4 import BeautifulSoup as bs
import pickle
import os
GOOGLE_CHROME_BIN = os.environ.get('GOOGLE_CHROME_BIN')
CHROMEDRIVER_PATH = os.environ.get('CHROMEDRIVER_PATH')
opts = ChromeOptions()
opts.binary_location = GOOGLE_CHROME_BIN
opts.add_argument('--headless')
opts.add_argument('--disable-gpu')
opts.add_argument('--no-sandbox')
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,chrome_options=opts)
错误代码:
Traceback (most recent call last):
File "Monitoring.py", line 28, in <module>
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=opts)
File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /app/.chromedriver/bin/chromedriver unexpectedly exited. Status code was: 127
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Monitoring.py", line 84, in <module>
driver.quit()
NameError: name 'driver' is not defined