ClericPy / ichrome

Chrome controller for Humans, based on Chrome Devtools Protocol(CDP) and python3.7+.
https://pypi.org/project/ichrome/
MIT License
227 stars 29 forks source link

怎么更改浏览器语言 #119

Closed andyx666888 closed 1 year ago

andyx666888 commented 1 year ago

谢谢作者的辛苦工作 我想问一下 怎么更改浏览器的语言 , 我在谷歌浏览器里面设置了english , 可以启动ichrome显示的确实中文 怎么更改ichrome 启动时使用英文呢

ClericPy commented 1 year ago
  1. 首先, ichrome 启动的 chrome 用的不是默认的 User dir, 所以和你的那个 Default Profile 可能不一样, 你可以考虑先启动 ichrome 的浏览器在里面设置语言
  2. 当然也可以对单个 Tab 设置, 见下面代码
  3. 还有就是启动的时候加命令行参数, --lang=locale, 或者 --accept-lang=en-US 这个东西放到 extra_config 参数里就行了
  4. 还有就是系统环境变量 LANGUAGE=en, 没试过
# 模拟地理位置=美国
await tab.send('Emulation.setLocaleOverride',
                locale='en_US')
# 设置地理坐标
await tab.send('Emulation.setGeolocationOverride',
                kwargs={
                    'accuracy': 100,
                    'latitude': 39.11884413294521,
                    'longitude': -77.33412341617008,
                })
# America/Chicago 时区
await tab.send('Emulation.setTimezoneOverride',
                timezoneId='America/Chicago')
# 模拟 UserAgent, 然后接受语言 en
await tab.send('Emulation.setUserAgentOverride',
                userAgent=UA,
                acceptLanguage='en')
await tab.send('Network.setExtraHTTPHeaders',
                headers={'Accept-Language': 'en'})
andyx666888 commented 1 year ago

多谢作者个及时回复 用 启动时加上 extra_config=["--lang=en-US"] 可以了