1 回答
TA贡献1865条经验 获得超7个赞
更改脚本中的浏览器首选项/选项语言
例
import time
from selenium import webdriver
def example():
fire_fox_profile = webdriver.FirefoxProfile()
fire_fox_profile.set_preference('intl.accept_languages', 'es-mx, es')
firefox_browser = webdriver.Firefox(executable_path=r'geckodriver.exe',
firefox_profile=fire_fox_profile)
firefox_browser.get('https://www.google.es/')
time.sleep(3) # wait page to load 3 sec
search = firefox_browser.find_element_by_name('q')
search.send_keys('apple pie')
search.submit()
if __name__ == "__main__":
example()
https://chromedriver.chromium.org/capabilities
import time
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', {'intl.accept_languages': 'es'})
chrome_browser = webdriver.Chrome(options=chrome_options)
chrome_browser.get('https://www.google.es/')
time.sleep(2) # wait page to load 3 sec
search = chrome_browser.find_element_by_name('q')
search.send_keys('apple pie')
search.submit()
添加回答
举报