我试图通过使用selenium的调度器运行脚本,但它显示以下错误消息: Service /app/.apt/opt/google/chrome/chrome意外退出。状态代码是:-6我已经使用了这两个构建包- https://github.com/heroku/heroku-buildpack-chromedriver.git https://github.com/heroku/heroku-buildpack-xvfb-google-chrome
脚本是:
chrome_exec_shim = "/app/.apt/opt/google/chrome/chrome"
opts = webdriver.ChromeOptions()
opts.binary_location = chrome_exec_shim
driver = webdriver.Chrome(executable_path=chrome_exec_shim, chrome_options=opts)发布于 2018-01-24 14:54:55
你应该做的是下载Chrome驱动程序here。你可以把它放在chrome包中,这样你根本不需要设置路径。(在我的经验中,最好放在路径中),或者你可以只给出下载驱动的路径,它可以在项目文件夹中(推荐)。
只需将变量chrome_exec_shim更改为驱动程序的路径即可。
发布于 2018-01-24 17:08:14
下载chromedriver后,出现未找到二进制文件的错误。在可执行文件路径中给出了chrome的地址,并在chrome选项中给出了chrome驱动程序的路径。这也导致了错误,在chrome选项中添加了--disable-gpu和--no-sandbox参数后,它得到了解决。谢谢你的帮助。:)最后运行的代码如下-
from selenium import webdriver
import os
chrome_exec_shim = os.environ.get("GOOGLE_CHROME_BIN", "chromedriver")
opts = webdriver.ChromeOptions()
opts.binary_location = chrome_exec_shim
opts.add_argument('--disable-gpu')
driver = webdriver.Chrome(executable_path='/app/development/chromedriver', chrome_options=opts)发布于 2018-01-24 18:39:23
chrome_exec_shim = "/app/.apt/opt/google/chrome/chrome"
opts = webdriver.ChromeOptions()
opts.binary_location = chrome_exec_shim
opts.addArguments("--no-sandbox");
opts.addArguments("--disable-gpu");
driver = webdriver.Chrome(executable_path=chrome_exec_shim, chrome_options=opts)尝试使用此代码。您必须添加chromeoption的参数,它才能正常工作。我试过了,它对我很有效。
https://stackoverflow.com/questions/48416364
复制相似问题