Created
January 16, 2019 16:21
-
-
Save ShaikeA/03e5eb66dc65a49aa196dc9fb602ffeb to your computer and use it in GitHub Desktop.
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
# Create a dict of accept headers for each user-agent. | |
accepts = {"Firefox": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
"Safari, Chrome": "application/xml,application/xhtml+xml,text/html;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5"} | |
# Get a random user-agent. We used Chrome and Firefox user agents. | |
# Getting a user agent using the fake_useragent package | |
ua = UserAgent() | |
if random.random() > 0.5: | |
random_user_agent = ua.chrome | |
else: | |
random_user_agent = ua.firefox | |
valid_accept = accepts['Firefox'] if random_user_agent.find('Firefox') > 0 else accepts['Safari, Chrome'] | |
headers = {"User-Agent": random_user_agent, | |
"Accept": valid_accept} | |
# See below for the complete function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment