【问题标题】:How to keep the selenium session alive in heroku?如何让 selenium 会话在 heroku 中保持活跃?
【发布时间】:2021-02-05 01:52:43
【问题描述】:

我已经在 heroku 中部署了 python 应用程序。该应用程序主要使用硒。每当我打开应用程序时,它都会开始新的 selenium 会话。我想在同一个硒会话中发生,这怎么可能? 这是我的 chrome_options。

options = Options()
options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
options.add_argument("--disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument('--single-process')
options.add_argument('--disable-gpu')
options.add_argument('--remote-debugging-port=9222')
options.add_argument('--disable-browser-side-navigation')
browser = webdriver.Chrome(options=options, executable_path=os.environ.get("CHROMEDRIVER_PATH"))
options.add_argument("--example-flag")

过程文件

web gunicorn app:app

【问题讨论】:

  • 你能显示Prcofile吗?
  • @Darkknight 添加

标签: python selenium selenium-webdriver heroku selenium-chromedriver


【解决方案1】:

这取决于您如何终止会话

# close the browser window which is currently in focus.
webdriver.close()

# close the browser and terminates the session
webdriver.quit()

在第一种情况下(close() 方法),每次执行都会打开一个新选项卡,而 Webdriver 会话仍处于活动状态

【讨论】:

    【解决方案2】:

    好的,我认为你还没有定义工人的问题。所以默认情况下Gunicorn 启动三个工作人员,这意味着在你的情况下三个 selenium 会话,所以将工作人员限制为一个并设置超时

    web gunicorn app:app --workers=1 --timeout=50

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 2022-10-13
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      • 2014-05-19
      • 1970-01-01
      相关资源
      最近更新 更多