It is not essential at all, and it is only necessary to pass the path so that PhantomJS can be used in the development environment, but due to various circumstances, the path could not be passed to the development environment, so we will implement it as a provisional measure.
if os.uname()[1] == "local host name":
driver = webdriver.PhantomJS(executable_path='/Applications/phantomjs-1.9.2-macosx/bin/phantomjs')
else:
driver = webdriver.PhantomJS()
When I upload the above source to Heroku and execute it without thinking about anything, the following error occurs as expected.
app[web.1]: driver = webdriver.PhantomJS()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/phantomjs/service.py", line 76, in start
app[web.1]: raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
app[web.1]: selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 2] No such file or directory: 'phantomjs'
When I entered Heroku and confirmed, PhantomJS was not created.
bash-3.2$ heroku run bash
Running bash on hogehoge... up, run.3889
~ $ pwd
/app
~ $ ls
app.py Procfile python-stack requirements.txt views
ghostdriver.log python python-version runtime.txt
~ $ PhantomJS
bash: PhantomJS: command not found
~ $ Phantomjs
bash: Phantomjs: command not found
Set buildpack.
Once you've done this, upload to Heroku.
bash-3.2$ git push heroku master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 335 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching custom git buildpack... done
remote: -----> Multipack app detected
remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-python
remote: =====> Detected Framework: Python
remote: -----> Installing runtime (python-3.4.3)
remote: -----> Installing dependencies with pip
remote: Collecting bottle==0.12.8 (from -r requirements.txt (line 1))
remote: Downloading bottle-0.12.8.tar.gz (69kB)
remote: Collecting Jinja2==2.8 (from -r requirements.txt (line 2))
remote: Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
remote: Collecting lxml==3.4.4 (from -r requirements.txt (line 3))
remote: Downloading lxml-3.4.4.tar.gz (3.5MB)
remote: Collecting MarkupSafe==0.23 (from -r requirements.txt (line 4))
remote: Downloading MarkupSafe-0.23.tar.gz
remote: Collecting selenium==2.48.0 (from -r requirements.txt (line 5))
remote: Downloading selenium-2.48.0.tar.gz (805kB)
remote: Collecting wheel==0.26.0 (from -r requirements.txt (line 6))
remote: Downloading wheel-0.26.0-py2.py3-none-any.whl (63kB)
remote: Installing collected packages: bottle, MarkupSafe, Jinja2, lxml, selenium, wheel
remote: Running setup.py install for bottle
remote: Running setup.py install for MarkupSafe
remote: Running setup.py install for lxml
remote: Running setup.py install for selenium
remote: Successfully installed Jinja2-2.8 MarkupSafe-0.23 bottle-0.12.8 lxml-3.4.4 selenium-2.48.0 wheel-0.26.0
remote:
remote: =====> Downloading Buildpack: https://github.com/stomita/heroku-buildpack-phantomjs
remote: =====> Detected Framework: PhantomJS
remote: -----> Extracting PhantomJS 1.9.8 binaries to /tmp/build_57462938b8344afe2a9119824547eac1/vendor/phantomjs
remote: -----> exporting PATH and LIBRARY_PATH
remote: Using release configuration from last framework (PhantomJS).
remote: -----> Discovering process types
remote: Procfile declares types -> renderer, web
remote: Default types for Multipack -> console
remote:
remote: -----> Compressing... done, 59.0MB
remote: -----> Launching... done, v8
remote: https://hogehoge.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/hogehoge.git
71335d7..c897730 master -> master
If you log in to Heroku's bash remotely, you'll see that a "vendor" folder has been created.
bash-3.2$ heroku run bash
Running bash on hogehoge... up, run.6077
~ $ pwd
/app
~ $ ls
app.py Procfile python-stack requirements.txt vendor
ghostdriver.log python python-version runtime.txt views
~ $
I accessed the URL in this state and confirmed the operation safely.
Recommended Posts