2017-07-07 1 views
2

J'ai une application de noeud fonctionnant sur Heroku. Je suis en train de gratter un site Web en utilisant du sélénium en python et en appelant le script python à partir de mon application de nœud chaque fois que j'en ai besoin. J'ai installé PhantomJS sur mon mac et quand je lance l'application localement (node ​​index.js), tout fonctionne très bien.Chemin PhantomJS sur Heroku

path_to_phantom = '/Users/govind/Desktop/phantomjs-2.1.1- 
macosx/bin/phantomjs' 

browser = webdriver.PhantomJS(executable_path = path_to_phantom) 

Cependant, rien ne semble fonctionner sur Heroku. J'ai également ajouté le PhantomJS buildpack à mon application de noeud mais il n'appelle tout simplement pas le script Python. Le problème que je pense est le chemin à PhantomJS buildpack. Quel chemin dois-je ajouter? Ou y a-t-il un autre aspect qui me manque ici?

+0

Avez-vous réussi à résoudre ce problème? J'ai le même problème. – simeg

+0

Malheureusement, non. – Govind

+0

J'ai réussi à résoudre ce problème. Vois ma réponse. – simeg

Répondre

1

j'ai réussi à utiliser Selenium avec PhantomJS dans mon application Python déployée à Heroku, procédez comme suit:

1) Passer à l'aide de la pile Cedar-14 sur ma demande Heroku

$ heroku stack:set cedar-14 

2) Installez un PhantomJS buildpack

$ heroku buildpacks:add https://github.com/stomita/heroku-buildpack-phantomjs 

Avec ces changements que je pourrais alors utiliser sélénium pour aller chercher des sites Web

from selenium import webdriver 

browser = webdriver.PhantomJS() 
browser.get("http://www.google.com") # This does not throw an exception if it got a 404 

html = browser.page_source 
print html # If this outputs more than just '<html><head></head><body></body></html>' you know that it worked