镀铬选项在加载页面时不适用

发布于 2025-02-12 23:27:57 字数 1061 浏览 0 评论 0原文

我正在尝试使用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:
enter image description here

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:
enter image description here

From here on, all of the webpages gets translated, even the initial one, as you can see:
enter image description here

Why didn't it work earlier when the page loaded? How do I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熊抱啵儿 2025-02-19 23:27:57

如此张贴设置语言选项应解决以下内容:

myoptions.add_argument("--lang=en")

As described in this post setting the language option should fix this:

myoptions.add_argument("--lang=en")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文