简体   繁体   中英

How to deploy Selenium-python on Heroku

So I'm trying to deploy on heroku my app that uses node.js and python. it works on my computer but when i try to run it on heroku i get an error:

    from selenium import webdriver
ImportError: no module named selenium

I have added Chrome, chromedriver, and selenium as buildpacks and in my Procfile i even have:

worker: pip install selenium
worker: python scraper.py

I am current just trying to get my python to work as i have already confirmed my javascript works.

module dependencies don't go in the procfile , they go in the requirement.txt file on the root of your project.

When you deploy on Heroku, you should see the log of the modules that were installed.

Also, you probably don't want to use Chromedriver unless you're running Chrome Headless on Heroku, because Heroku cannot open a browser on the server: it has no graphic interface.

You might want to use something like PhantomJS or Chrome Headless to make this work.

The best way i found after along search over the internet, is using PhantomJs() web driver from selenium

from selenium import webdriver
driver = webdriver.PhantomJS()

#your code here

driver.quit()

and then use this buildpackge https://github.com/stomita/heroku-buildpack-phantomjs

$ heroku create --stack cedar --buildpack https://github.com/stomita/heroku-buildpack-phantomjs.git

# or if your app is already created:
$ heroku buildpacks:add https://github.com/stomita/heroku-buildpack-phantomjs

$ git push heroku master

and it shall work for you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM