简体   繁体   中英

How to translate a web page using selenium firefox and chrome driver in python?

I tried to translate a page into English by using firefox driver and chrome driver. But I am not able to do it. Here is my code:

    from selenium.webdriver.firefox.options import Options
    from selenium import webdriver    

    #Firefox driver settings
    options = Options()
    options.headless = True

    profile = webdriver.FirefoxProfile()
    profile.set_preference('intl.accept_languages', 'en-US, en')
    browser = webdriver.Firefox(options=options,firefox_profile=profile)

    browser.maximize_window()

    browser.get('https://www.baidu.com/')

from selenium.webdriver.firefox.options import Options from selenium import webdriver

#Firefox driver settings
options = Options()
options.headless = True

profile = webdriver.FirefoxProfile()
profile.set_preference('intl.accept_languages', 'en-US, en')
browser = webdriver.Firefox(options=options,firefox_profile=profile)

browser.maximize_window()

browser.get('https://www.baidu.com/')

Try with "en-GB", hope it helps

options = Options()
options.headless = True

profile = webdriver.FirefoxProfile()
profile.set_preference('intl.accept_languages', 'en-GB')
browser = webdriver.Firefox(options=options,firefox_profile=profile)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM