简体   繁体   中英

Selenium Headless Chrome and Language Setup

i'm working with selenium and the chrome driver in python. I can setup the language of my chrome browser like this:

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

This works like a charm, but as soon as i add the headless argument i get results in german again:

options.add_argument("--headless")

Thank you guys for your time.

Using to set the language pass the --lang command using an instance of Options() as follows:

from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--lang=en_US')

Reference

You can find a relevant detailed discussion in:

there is no tags for debian but still, maybe it will help someone.

  1. Installed the web browser - language packs . The package is called chromium-l10n on Debian 11.

  2. Made sure the locale i want is shown via locale -a (uncomment in /etc/locale.gen and use locale-gen ).

  3. Started the python program via:

     LANGUAGE=de programname.py
    • as alternative, setting LANGUAGE inside the python also worked.

       from os import environ environ['LANGUAGE'] = 'de'

This made it work in Headless mode.

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