在Heroku Python中为Chromedriver添加扩展

2024-09-27 07:19:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经成功地在Heroku上设置了以下应用程序chromedriver

我想通过webdriver选项添加一些扩展(myextension.crx)

你能帮忙吗?(请选择要使用的路径和步骤)

I.e

options = webdriver.ChromeOptions()
options.add_extension('./myextension.crx')

#Heroku Chromedriver Set Up
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


CHROMEDRIVER_PATH = "/app/.chromedriver/bin/chromedriver"
chrome_bin =os.environ.get('GOOGLE_CHROME_SHIM', None)
options = webdriver.ChromeOptions()
options.binary_location = chrome_bin
options.add_argument(" — disable-gpu")
options.add_argument(" — no-sandbox")
options.add_argument(" — headless")
options.add_argument('--disable-dev-shm-usage') 
options.add_argument('--remote-debugging-port=9222')
options.add_argument('--disable-infobars')

driver = webdriver.Chrome(executable_path="chromedriver", chrome_options=options)

还使用了官方的构建包

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

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

和变量

CHROMEDRIVER_PATH=/app/.CHROMEDRIVER/bin/CHROMEDRIVER

GOOGLE\u CHROME\u BIN=/app/.apt/usr/BIN/GOOGLE CHROME


Tags: addappherokubingooglechromeargumentchromedriver

热门问题