Running ChromeDriver with Python Selenium on Heroku

So, I have a Flask server on Heroku that has been working fine, as expected for some time. Now, according to the new requirements, I need to add functionality to the Flask server to retrieve the page from an external website. For reasons, I know that I use Selenium along with the Chrome browser for this. I usually managed to install this and it works fine, but I'm completely unsure how to configure it on the Heroku server. I read a little about buildpacks and found this buildpack for ChromeDriver:

https://elements.heroku.com/buildpacks/jimmynguyc/heroku-buildpack-chromedriver

However, I am not sure how to proceed further. How can I install the Chrome browser myself and what else is needed to link it all?

+9
source share
1 answer

I had the same problem and the following steps worked well for me:

  • I added the following build packages on heroku: https://github.com/heroku/heroku-buildpack-xvfb-google-chrome (for installing chrome, since chromedriver requires it) and https://github.com/heroku/heroku - buildpack-chromedriver .
  • I created the GOOGLE_CHROME_BIN environment variable with the chrome path on heroku: /app/.apt/usr/bin/google-chrome and the CHROMEDRIVER_PATH environment variable with the chromedriver path on heroku: /app/.chromedriver/bin/chromedriver.
  • In my python file, I configured chromedriver:

    chrome_options = Options()
    chrome_options.binary_location = GOOGLE_CHROME_BIN
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--no-sandbox')
    driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=chrome_options)
    

( chromedriver , : " Chrome: ". --Disable-gpu --no-sandbox ).

+14

Source: https://habr.com/ru/post/1663318/


All Articles