python - Heroku 上的 PhantomJS 路径

标签 python node.js selenium heroku phantomjs

我有一个在 Heroku 上运行的 Node 应用程序。我正在 python 中使用 selenium 抓取一个网站,并在需要时从我的 Node 应用程序调用 python 脚本。我在我的 Mac 上安装了 PhantomJS,当我在本地运行该应用程序 (node index.js) 时,一切正常。

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

browser = webdriver.PhantomJS(executable_path = path_to_phantom)

但是,在 Heroku 上似乎没有任何效果。我还添加了 PhantomJS buildpack到我的 Node 应用程序,但它只是不调用 python 脚本。我认为问题是 PhantomJS buildpack 的路径。我应该添加什么路径?或者我还遗漏了其他方面吗?

最佳答案

按照以下步骤,我设法在部署到 Heroku 的 Python 应用程序中将 Selenium 与 PhantomJS 结合使用:

1) 切换到在我的 Heroku 应用程序上使用 Cedar-14 堆栈

$ heroku stack:set cedar-14

2) 安装 PhantomJS 构建包

$ 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

关于python - Heroku 上的 PhantomJS 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44960968/

相关文章:

node.js - 通过父键查询实体

javascript - 如果 Grunt 任务的子任务之一失败,如何使其失败?

python - 过滤值的访问索引

python - 值错误 : too many values to unpack , 电子邮件验证

node.js - Nodejs View 猜测多个扩展名

django - 使用 South/Selenium 进行 Django 测试的装置

java - org.openqa.selenium.SessionNotCreatedException:无法创建新的远程 session 。在模拟器中初始化android驱动程序时

java - 关于Cucumber框架

python - 错误 : raise ValueError ("No element found in %s" % response) occur when try to login with scrappy

python - 如何使用 python 提取封闭的 zip