Random User Agent
This Python library provides lists of user agents based on filters such as operating system, software name, and popularity. It currently holds a collection of over 326,000 user agents. The library's last release was version 1.0.1 in December 2018, making its user agent data significantly outdated for modern web scraping and automation tasks.
Warnings
- breaking The library has not been updated since December 2018. As user agent strings evolve rapidly with new browser and OS versions, the data provided by this library is severely outdated. Using these old user agents in modern web scraping or automation tasks is highly likely to lead to detection or incorrect rendering.
- gotcha The project is no longer actively maintained, with the last commit dating back to 2018. This means there will be no bug fixes, feature updates, or updates to its internal user agent database, which is crucial for the utility of such a library.
Install
-
pip install random_user_agent
Imports
- UserAgent
from random_user_agent.user_agent import UserAgent
- SoftwareName, OperatingSystem
from random_user_agent.params import SoftwareName, OperatingSystem
Quickstart
from random_user_agent.user_agent import UserAgent
from random_user_agent.params import SoftwareName, OperatingSystem
# Define desired filters
software_names = [SoftwareName.CHROME.value, SoftwareName.FIREFOX.value]
operating_systems = [OperatingSystem.WINDOWS.value, OperatingSystem.LINUX.value]
# Initialize the UserAgent rotator with filters and a limit
user_agent_rotator = UserAgent(
software_names=software_names,
operating_systems=operating_systems,
limit=10 # Get 10 random user agents
)
# Get a list of user agents
user_agents = user_agent_rotator.get_user_agents()
# Print some user agents
for i, ua in enumerate(user_agents[:3]):
print(f"User Agent {i+1}: {ua}")
# Get a single random user agent
single_ua = user_agent_rotator.get_random_user_agent()
print(f"\nSingle Random User Agent: {single_ua}")