from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('general.useragent.override', 'whatever you want')
driver = webdriver.Firefox(profile)
Change user agent for selenium driver