I'm trying to scrape an Amazon French page using Selenium. I want this page to be translated from French to English upon loading. I have attempted to do that using following code:
myoptions = webdriver.ChromeOptions()
prefs = {
"translate_whitelists": {"fr":"en"},
"translate": {"enabled":"true"}
}
myoptions.add_experimental_option("prefs", prefs)
path = r'C:\chromedriver.exe'
browser = webdriver.Chrome(executable_path=path, options=myoptions)
browser.get("https://www.amazon.fr/dp/0001002791")
However, when the page loads, it still shows up in French, as you can see in the image below:
Now, if I navigate to any other link from this webpage, the option to translate the webpage works and the icon shows in the search bar. Plus, the message of translation also pop ups as shown below:
From here on, all of the webpages gets translated, even the initial one, as you can see:
Why didn't it work earlier when the page loaded? How do I fix this?
CodePudding user response: