本文介绍了在Heroku中使用gem Watir-找不到Chrome二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用宝石Watir提取Heroku中的数据,但是我遇到以下问题:

I am trying to scrap data in Heroku with the gem Watir but I have the following problem :

Selenium::WebDriver::Error::UnknownError (unknown error: cannot find Chrome binary

2018-06-12T17:29:54.221948+00:00 app[web.1]:   (Driver info: chromedriver=2.40.565383 

我正在使用这两个buildpackers:

I am using those 2 buildpackers :

  • https://github.com/heroku/heroku-buildpack-google-chrome
  • https://github.com/heroku/heroku-buildpack-chromedriver

我不知道如何在Rails项目中修复路径.遵循此文档: https://github.com/heroku/heroku-buildpack -google-chrome#selenium

I don't understand how to fix the path in my rails project. As following this doc : https://github.com/heroku/heroku-buildpack-google-chrome#selenium

似乎我必须添加此路径

/app/.apt/usr/bin/google-chrome

但是我根本不知道该在哪里添加.

But I don't understand at all where I have to add this.

如果有人有解决方案:)谢谢!

If someone have the solution :) Thank you !

推荐答案

我终于找到了问题所在!

I finally find what's wrong !

安卡(Anka)的以下答案适用于我的情况:

The following answer by Anka is working for my case :

Ruby/Heroku Selenium :: WebDriver ::错误:: WebDriver错误:无法连接到chromedriver 127.0.0.1:9516

添加以下2个buildpack:

Add the 2 following buildpacks :

https://github.com/heroku/heroku-buildpack-chromedriver

https://github.com/heroku/heroku-buildpack-google-chrome

在.env文件中添加以下信息:

Add the following information in the .env file :

GOOGLE_CHROME_SHIM = '/app/.apt/usr/bin/google-chrome'

然后按如下所示调用Watir浏览器:

Then call the Watir Browser as following :

opts = {
    headless: true
  }

  if (chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil))
    opts.merge!( options: {binary: chrome_bin})
  end 

browser = Watir::Browser.new :chrome, opts

这篇关于在Heroku中使用gem Watir-找不到Chrome二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 20:52