Package: getuseragent
GetUserAgent - Random/Fake/Spoof Common User AgentsTable of ContentsGetUserAgent - Random/Fake/Spoof Common User AgentsIntroInstallationFeaturesUse CasesCode ExamplesInitialisationUser-Agents AvailableCombinationPrint Random User Agent From ListPerformance / LimitingRequests HandlerTo DoChangesIntroThis is just a simple python module to produce a random, commonly used user agents each time. It contains 11 lists for a total of 1,100 user agents. You can choose and combine lists depending on your needs.InstallationAssumes you have python3 installed.pip install getuseragentFeaturesGet a random user agent of Chrome, Firefox, Safari, Edge, IE, Android, iOS, Windows, Mac, Linux, Desktop, Mobile, Bots, or any combinationUser-Agents from 100 of the most commonly usedAdd requests handler prefixSpoofed or fake user agentsCombine multiple user agent listsUse CasesCheck that your website statistics are identifying browsers correctlyHandle bots visiting your websiteMaking a security system to detect fake user agents?Code ExamplesInitialisationfromgetuseragentimportUserAgentuseragent=UserAgent()theuseragent=useragent.Random()print(theuseragent)Example output:Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148User-Agents AvailableEach of the following lists contains 100 commonly used user agents for that software/device/system.# Firefoxuseragent=UserAgent("firefox")# Chromeuseragent=UserAgent("chrome")# Safariuseragent=UserAgent("safari")# Internet Explorer (IE)useragent=UserAgent("ie")# Edgeuseragent=UserAgent("edge")# iOSuseragent=UserAgent("ios")# Androiduseragent=UserAgent("android")# Windowsuseragent=UserAgent("windows")# Macuseragent=UserAgent("mac")# Linuxuseragent=UserAgent("linux")Sets including multiple lists:# Desktop (Windows + Mac + Linux)useragent=UserAgent("desktop")# Mobile (iOS + Android)useragent=UserAgent("mobile")# All (Everything except bots)useragent=UserAgent()# oruseragent=UserAgent("all")Bots like web crawlers:# Botsuseragent=UserAgent("bots")CombinationYou can combine lists and sets together. Use the + sign between list names. Duplicate lists will automatically be removed so there's only 1 of each list at most.Examples:# Chrome and Edge and iOSuseragent=UserAgent("chrome+edge+ios")# Mobile + Firefoxuseragent=UserAgent("mobile+firefox")# All + Botsuseragent=UserAgent("all+bots")# Print a random user agent based on your selection:print(useragent.Random())Print Random User Agent From ListYou can print a single random user agent like so:# Initialiseuseragent=UserAgent()# Get one random user agentua=useragent.Random()# Print user agentprint(ua)Performance / LimitingYou can limit the total amount of user agents in the list to save memory. The default is no limit, and each list has 100 commonly used user agents.# Using 3 lists would make the total available user agents 300useragent=UserAgent("chrome+firefox+ios")# You can limit the total to, for example, 50:# (List is randomised before truncating)useragent=UserAgent("chrome+firefox+ios",total=50)# You can limit individual lists# This would give 10 firefox user agents + 10 safari user agents# The total amount of user agents available would be 20useragent=UserAgent("firefox+safari",limit=10)# You can combine limit and total# This would get 10 user agents for both android and ie, for 20 user agents# The list would be randomised, then reduced to 15 total available user agentsuseragent=UserAgent("android+ie",limit=10,total=15)# Print a random user agentprint(useragent.Random())Requests HandlerYou can enable the option to return your user agents ready to be used with the requests module.# ExampleimportrequestsfromgetuseragentimportUserAgentmyuseragent=UserAgent("all",requestsPrefix=True).Random()# Example Output:# --# {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0'}page=requests.get("https://google.com",headers=myuseragent)To DoError handlingRetrieve updated, most popular user-agents from the internetBetter performanceHot-swappable listsCustom list(s)Command line argumentsImprove ReadmeChanges0.0.7 (June 9th, 2021)1. Added individual list limits, which can be used when using one or multiple lists.
For example, if you used:

UserAgent("firefox+ios", limit=5)

It would limit each list to 5 user agents, and two lists, bringing the total user agents 10.

2. Checks if user agent files exist.
3. Checks if user list empty in Random()0.0.2 - 0.0.6Fixed package errors, spelling mistakes0.0.1Initial release