I've created a script in python in combination with selenium to scrape different app names from google play store and they all are coming through when I execute my script. However, the result are being converted into my native language that is not English.
How can I modify the language option in selenium python bindings?
My attempt (tried to change the language option but failed):
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
link = 'https://play.google.com/store'
chrome_options = Options()
chrome_options.add_argument("accept-language=en-US")
with webdriver.Chrome(options=chrome_options) as driver:
driver.get(link)
for item in wait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,'.details a.title'))):
print(item.text)
The output I'm having are in my native language which is not english.
The term language binding generally refers to mapping a software library/API to another language in the manner to be used in two different developing ecosystems and/or environments with the same functionalities. The number of Selenium users has grown significantly over time.
For Selenium to switch to a particular window, one needs to use the switch_to_window method. Pass the window handle ID of the target tab where the user wants to switch as an argument to that method.
Not Working:
I've tried the --lang, but it didn't worked for me:
chrome_options.add_argument("--lang=en")
OR
chrome_options.add_argument("--lang=en-US")
Working Solution:
After some research I found that to solve this, we have to use the experimental option intl.accept_languages:
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
driver = webdriver.Chrome(chrome_options=options)
Note: To use above, your website should need to support the same.
There is one more way to achieve the same by translating your native language page to english:
Try using below code:
prefs = {
"translate_whitelists": {"your native language":"en"},
"translate":{"enabled":"True"}
}
options.add_experimental_option("prefs", prefs)
I think your syntax for setting the language is off. Instead of
chrome_options.add_argument("accept-language=en-US")
Try
chrome_options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
Second Round
Looks like english isn't available in 'intl.accept_languages'
yet. But after a little more searching I found the following might work--give it a try?
chrome_options.add_argument("--lang=en-US")
Third round
Try using --lang=en-GB as Fenio suggests:
chrome_options.add_argument("--lang=en-GB")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With