Skip to content

Instantly share code, notes, and snippets.

@jamespo
Created August 14, 2024 08:49
Show Gist options
  • Save jamespo/b7cb9223dc7382e31ce26baf3f78c90e to your computer and use it in GitHub Desktop.
Save jamespo/b7cb9223dc7382e31ce26baf3f78c90e to your computer and use it in GitHub Desktop.
Setting a custom user agent in Python Selenium
#!/bin/env python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
user_agent='Fake Browser'
myoptions = Options()
myoptions.add_argument(argument=f'--user-agent={user_agent}')
driver = webdriver.Chrome(options=myoptions)
driver.get("https://www.google.com")
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment