【问题标题】:Set browser locale in headless chrome with python使用 python 在无头 chrome 中设置浏览器语言环境
【发布时间】:2020-04-20 09:20:25
【问题描述】:

我在 docker 容器中使用 python 脚本运行 headless chrome。浏览器以本地语言打开,而不是我在代码中指定的语言。

我正在使用实验选项,但它不起作用。

options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})

这也不起作用:

options.add_argument('--lang=es')

或者这个:

browser_locale = 'en'
options.add_argument("--lang={}".format(browser_locale))

帮助表示赞赏。

【问题讨论】:

    标签: python browser selenium-chromedriver locale headless


    【解决方案1】:

    最终,我找到了解决方案:

    在我的create_driver 方法中,我添加了self.driver.get("https://www.google.com/ncr"),它解决了以本地语言打开浏览器的问题。

    NCR 代表 NoCountryRedirect。

    【讨论】:

      猜你喜欢
      • 2016-09-10
      • 1970-01-01
      • 2012-06-27
      • 2020-01-24
      • 1970-01-01
      • 2013-01-10
      • 2020-04-05
      相关资源
      最近更新 更多