Created
August 14, 2024 08:49
-
-
Save jamespo/b7cb9223dc7382e31ce26baf3f78c90e to your computer and use it in GitHub Desktop.
Setting a custom user agent in Python Selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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