首页 > 解决方案 > 如何将 chromedriver 添加到我的 github 存储库

问题描述

基本上我想学习如何将我的 chromedriver 添加到我的 github 存储库中,以便人们可以在他们的应用程序上运行我的 python 脚本。

我已经下载了 chromedriver for linux 并通过本地路径执行它。

我看到人们将 chromedriver_installer 添加到他们的 requirements.txt 中,但用户必须手动更改脚本以添加安装 chromedriver 的路径。有没有办法自动做到这一点?

那么将它添加到我的项目并使其能够在每台机器上运行的最佳方法是什么?

标签: seleniumgithubselenium-chromedriver

解决方案


我喜欢使用chromedriver-autoinstaller。这非常简单,只需使用 pip 安装,您就可以像这样在代码中使用它,而无需实际安装/推送到您的仓库中的 chromedriver。

from selenium import webdriver
import chromedriver_autoinstaller

chromedriver_autoinstaller.install()

#Chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument('--disable-dev-shm-usage')

#Run chrome
driver = webdriver.Chrome(options=chrome_options)

# do the code for your test

推荐阅读