镀铬选项在加载页面时不适用
我正在尝试使用Selenium刮擦亚马逊法语页面。我希望加载后将此页面从法语翻译成英文。我尝试使用以下代码来做到这一点:
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")
现在,如果我从此网页导航到任何其他链接,则可以翻译网页的选项作品和图标在搜索栏中显示。另外,翻译的消息还弹出了UPS,如下所示:
页面加载时为什么不较早起作用?我该如何解决?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如此张贴设置语言选项应解决以下内容:
As described in this post setting the language option should fix this: