Jack A
Jack A

Reputation: 109

Heroku and Selenium webdriver not working together

I have a flask app that i am trying to host on heroku. i am using selenium to grab data from a website. locally, it worked perfect, but now I am trying to deploy it using heroku, and having major problems. before all i did was point to the path of the webdriver on my local machine. now, I am using these 2 buildpacks - https://github.com/heroku/heroku-buildpack-chromedriver , and https://github.com/heroku/heroku-buildpack-google-chrome . I have no clue how to get it to work, but here is some code that i have found for another version (it doesnt work) -

chrome_options = Options()
        chrome_options.binary_location = os.environ['GOOGLE_CHROME_BIN']
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('-- headless')
        browser = webdriver.Chrome(executable_path= os.environ['CHROMEDRIVER_PATH, chrome_options=chrome_options'])

I have no idea if this is correct or even close to it.

Upvotes: 0

Views: 2651

Answers (2)

Ronnie
Ronnie

Reputation: 1092

I've posted an answer with chromedriver usage on heroku >> here

Not sure if even after getting chrome buildpack to work, you'll be successfully able to scrape the data. Instead use firefox buildpack. I would suggest this buildpack

Type in heroku buildpacks:add https://github.com/pyronlaboratory/heroku-integrated-firefox-geckodriver to add in your heroku slug and get started with firefox and geckodriver in your application code.

Upvotes: 0

Angela L.
Angela L.

Reputation: 151

option = webdriver.ChromeOptions()

# You will need to specify the binary location for Heroku 
option.binary_location = os.getenv('GOOGLE_CHROME_BIN')

option.add_argument("--headless")
option.add_argument('--disable-gpu')
option.add_argument('--no-sandbox')
browser = webdriver.Chrome(executable_path=os.getenv('CHROME_EXECUTABLE_PATH'), options=option)

  1. Add two buildpacks:
  2. Add Config Vars:
    • GOOGLE_CHROME_BIN=/app/.apt/usr/bin/google-chrome
    • CHROME_EXECUTABLE_PATH=/app/.chromedriver/bin/chromedriver

Upvotes: 2

Related Questions