Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python randomly chose user agent

import requests
import random
user_agent_list = [
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',
]
url = 'https://httpbin.org/headers'
for i in range(1,4):
#Pick a random user agent
user_agent = random.choice(user_agent_list)
#Set the headers 
headers = {'User-Agent': user_agent}
#Make the request
response = requests.get(url,headers=headers)
print("Request #%d
User-Agent Sent:%s

Headers Recevied by HTTPBin:"%(i,user_agent))
print(response.json())
print("-------------------")
Comment

PREVIOUS NEXT
Code Example
Python :: pyttsx3 female voice template 
Python :: django models using Value 
Python :: python delete white spaces 
Python :: create 2d array python list comprehension 
Python :: python close database connection 
Python :: python restart script 
Python :: open file python 
Python :: django creating calculated fields in model 
Python :: python remove all unicode from string 
Python :: case in python 
Python :: install python packages behind proxy 
Python :: python remove none from dict 
Python :: python reverse split only once 
Python :: sorting numbers in python without sort function 
Python :: measure execution time in ipython notebook 
Python :: how to use dictionary comprehension to make a dictionary for some names of a list in python 
Python :: django order by 
Python :: python cut string after character 
Python :: python fibonacci 
Python :: pandas merge on columns different names 
Python :: macos set default python version 
Python :: change directory in python script 
Python :: python list to string without brackets 
Python :: playsound python 
Python :: change variable type python 
Python :: how to create a virtual environment in python 3 
Python :: python debugger 
Python :: string to float python 
Python :: switching keys and values in a dictionary in python [duplicate] 
Python :: randomly choose between two numbers python 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =