我有一个 Django + Selenium 应用程序,我正在尝试部署到 Heroku。我有一个管理命令,可以激活 Selenium Webdriver 来使用。
每当我在本地运行它时,它都完全没问题(没有
headless
),但是在部署到 Heroku 后,无论我尝试什么,我都会得到:
Message: unknown error: net::ERR_CONNECTION_RESET
(Session info: headless chrome=116.0.5845.140)
我按如下方式实例化我的网络驱动程序:
...
logger.info("Starting selenium webdriver...")
options = Options()
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--enable-logging")
options.add_argument("--incognito")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--disable-extensions")
options.add_argument("--dns-prefetch-disable")
self.webdriver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()), options=options
)
我认为问题在于
headless
论点 - 然而,至少在本地添加它会破坏事情。
这是在 Heroku 上运行,所以我需要
headless
才能工作。
我真的很困惑。感谢任何帮助/建议 - 谢谢!
尝试替换 options.add_argument("--headless") =无头新