Skip to content

Instantly share code, notes, and snippets.

@simon-saliba
Created January 19, 2021 22:47
Show Gist options
  • Save simon-saliba/45c448a160d3ea5eb4228c2938092140 to your computer and use it in GitHub Desktop.
Save simon-saliba/45c448a160d3ea5eb4228c2938092140 to your computer and use it in GitHub Desktop.
Changing user-agent property after every request - 1
import requests
from selenium import webdriver
from fake_useragent import UserAgent
ua = UserAgent()
userAgent = ua.random
options.add_argument(f'user-agent={userAgent}')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome("/app/chromedriver_84_linux",options)
while(1):
driver.get("https://the-url-of-some-website")
# Do-Something-With-Website
driver.quit()
# Quit previous browser and spawn new browser with new user-agent
userAgent = ua.random
options.add_argument(f'user-agent={userAgent}')
driver = webdriver.Chrome("/app/chromedriver_84_linux",options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment