【问题标题】:Heroku and Selenium webdriver not working togetherHeroku 和 Selenium webdriver 不能一起工作
【发布时间】:2019-05-29 13:31:15
【问题描述】:

我有一个烧瓶应用程序,我试图在 heroku 上托管。我正在使用 selenium 从网站获取数据。在本地,它运行良好,但现在我正在尝试使用 heroku 部署它,并且遇到了重大问题。在我所做的只是指向本地机器上的 webdriver 的路径之前。现在,我正在使用这 2 个构建包 - https://github.com/heroku/heroku-buildpack-chromedriverhttps://github.com/heroku/heroku-buildpack-google-chrome 。我不知道如何让它工作,但这是我为另一个版本找到的一些代码(它不起作用) -

chrome_options = Options()
        chrome_options.binary_location = os.environ['GOOGLE_CHROME_BIN']
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('-- headless')
        browser = webdriver.Chrome(executable_path= os.environ['CHROMEDRIVER_PATH, chrome_options=chrome_options'])

我不知道这是否正确或接近它。

【问题讨论】:

    标签: python selenium heroku webdriver hosting


    【解决方案1】:
    option = webdriver.ChromeOptions()
    
    # You will need to specify the binary location for Heroku 
    option.binary_location = os.getenv('GOOGLE_CHROME_BIN')
    
    option.add_argument("--headless")
    option.add_argument('--disable-gpu')
    option.add_argument('--no-sandbox')
    browser = webdriver.Chrome(executable_path=os.getenv('CHROME_EXECUTABLE_PATH'), options=option)
    
    
    1. 添加两个构建包:
    2. 添加配置变量:
      • GOOGLE_CHROME_BIN=/app/.apt/usr/bin/google-chrome
      • CHROME_EXECUTABLE_PATH=/app/.chromedriver/bin/chromedriver

    【讨论】:

      【解决方案2】:

      我已经在 heroku >> here 上发布了关于 chromedriver 使用的答案

      不确定即使在让 chrome buildpack 工作之后,您是否能够成功地抓取数据。而是使用 firefox buildpack。我会建议这个buildpack

      输入heroku buildpacks:add https://github.com/pyronlaboratory/heroku-integrated-firefox-geckodriver 以添加您的heroku slug 并开始在您的应用程序代码中使用firefox 和geckodriver。

      【讨论】:

        猜你喜欢
        • 2016-01-01
        • 1970-01-01
        • 2020-05-27
        • 1970-01-01
        • 2018-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多