本文介绍了如何使用Python将通过Selenium Webdriver打开的网页转换为英语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,这是我的代码:

This is my code so far:

username_input = "username"
password_input = "password"
url='myurl'
browser = webdriver.Chrome(r'chromedriver.exe')
browser.get(url)
browser.maximize_window()
username = browser.find_element_by_id("j_username")
password = browser.find_element_by_id("j_password")
username.send_keys(str(username_input))
password.send_keys(str(password_input))
browser.find_element_by_xpath('//*[@id="inner-box"]/form/label[3]/input').click()
time.sleep(2)

一旦我用法语登录了所有内容,但是我需要用英语登录..我该怎么做?

Once I have logged in everything is in French but I need it in English.. how do I do this?

我尝试了多种操作,例如Chrome选项,但不了解/不起作用.

I have tried several things such as Chrome Options but didn't understand it/wasn't working.

任何帮助将不胜感激.

推荐答案

在下面添加 prefs 可将法语自动翻译为英语

add prefs below to auto translate french to english

options = Options()
prefs = {
  "translate_whitelists": {"fr":"en"},
  "translate":{"enabled":"true"}
}
options.add_experimental_option("prefs", prefs)
browser = webdriver.Chrome(chrome_options=options)

如果该位置与脚本位于同一文件夹中,则可以删除 r'chromedriver.exe'.

you can remove r'chromedriver.exe' if the location is in same folder with your script.

这篇关于如何使用Python将通过Selenium Webdriver打开的网页转换为英语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 19:17