【问题标题】:How to set path to chromedriver in heroku chromedriver buildpack如何在heroku chromedriver buildpack中设置chromedriver的路径
【发布时间】:2018-07-21 06:15:33
【问题描述】:

我正在尝试在 heroku 上设置 selenium。我一直在寻找Running ChromeDriver with Python selenium on Heroku 寻求帮助。基于此,我安装了列出的 2 个构建版本。我正在使用 cedar-14,因为不支持 16 堆栈。

当我跑步时:

$ heroku buildpacks
===  Buildpack URLs
1. heroku/python
2. https://github.com/heroku/heroku-buildpack-chromedriver
3. https://github.com/heroku/heroku-buildpack-xvfb-google-chrome

无论如何我都在尝试使用

https://github.com/heroku/heroku-buildpack-chromedriver/tree/master/bin

我的代码包含:

options = webdriver.ChromeOptions()
CHROMEDRIVER_PATH = os.getenv('$HOME') or basedir+'/chromedriver.exe'
FLASK_CONFIG = os.getenv('FLASK_CONFIG')

if FLASK_CONFIG and FLASK_CONFIG == "production":
    options.binary_location = os.getenv('$GOOGLE_CHROME_SHIM')
    options.add_argument('--disable-gpu')
    options.add_argument('--no-sandbox')

driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, options=options)

此代码在本地运行良好,但在 heroku 上:

 driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, options=options)

2018-02-10T16:37:32.121783+00:00 app[web.1]: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

如何在 buildpack 中设置 chromedriver 的路径?

【问题讨论】:

    标签: python selenium heroku selenium-chromedriver


    【解决方案1】:

    不确定 heroku-buildpack-xvfb-google-chrome buildpack;我正在使用 heroku/google-chrome

    你可以使用这个 sn-p 来配置你的定义

    import os
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    def load_chrome_driver(proxy):
    
          options = Options()
    
          options.binary_location = os.environ.get('GOOGLE_CHROME_BIN')
    
          options.add_argument('--headless')
          options.add_argument('--disable-gpu')
          options.add_argument('--no-sandbox')
          options.add_argument('--remote-debugging-port=9222')
          options.add_argument('--proxy-server='+proxy)
    
          return webdriver.Chrome(executable_path=str(os.environ.get('CHROMEDRIVER_PATH')), chrome_options=options)
    

    我正在使用代理,但您可以避免这种情况。使用heroku config:set命令设置如下路径

    CHROMEDRIVER_PATH=/app/.chromedriver/bin/chromedriverGOOGLE_CHROME_BIN=/app/.apt/usr/bin/google-chrome

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 2018-08-09
      • 1970-01-01
      • 2019-06-08
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      相关资源
      最近更新 更多