2017-07-07 99 views
2

我有一個在Heroku上運行的節點應用程序。我正在使用python中的selenium來抓取網站,並在需要時從我的節點應用程序中調用python腳本。我在我的Mac上安裝了PhantomJS,當我在本地運行應用程序(節點index.js)時,一切正常。Heroku上的PhantomJS路徑

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

browser = webdriver.PhantomJS(executable_path = path_to_phantom) 

但是,似乎在Heroku上沒有任何工作。我還將PhantomJS buildpack添加到我的節點應用程序,但它不會調用python腳本。我認爲這個問題是PhantomJS buildpack的路徑。我應該添加什麼路徑?還是我在這裏失蹤的其他方面?

+0

您是否設法解決這個問題?我有同樣的問題。 – simeg

+0

不幸的是,沒有。 – Govind

+0

我設法解決這個問題。看到我的答案。 – simeg

回答

1

我設法使用具有PhantomJS硒以下步驟部署到Heroku的我的Python應用:

1)切換到使用我的Heroku應用雪松-14堆棧

$ heroku stack:set cedar-14 

2)安裝一個PhantomJS buildpack

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

有了這些變化,然後我可以用Selenium來獲取網站

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 
相關問題