简体   繁体   中英

Set browser locale in headless chrome with python

I'm running headless chrome with python script, from docker container. Browser is opening in local language, instead of the language I have specified within the code.

I am using experimental option, but it doesn't work.

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

This doesn't work either:

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

Or this:

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

Help appreciated.

Eventually, I found the solution to be this:

In my create_driver method, I added self.driver.get("https://www.google.com/ncr") which resolved the issue of opening the browser in the local language.

NCR stands for NoCountryRedirect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM