Randomly generates a useragent for fetching a web page without a browser.
Project description
Randomly generate a fake useragent.
This project's idea is inspired by fake-useragent. I rewrote the whole codes in order to boost performance by:
- using
asyncio
andaiohttp
to improve fetching speed - taking advantage of
Xpath
to improve parsing speed - changing random choice algorithm to improve random choice speed
Supported browsers are: chrome, edge, firefox, safari, and opera. Browser name is case insensitive. Some other possible spellings of each browser are mapped to the right one (e.g. "ie" -> "edge", "google" -> "chrome").
Usage
On your terminal, just simply enter fakeua
In your python script, import the function. Every time you run the script, the useragent value will be different.
from fake_user_agent import user_agent
# Not specify a browser:
ua = user_agent()
# Specify a browser to randomly choose from:
ua = user_agent("chrome")
# It takes < 2s for the first run, including fetching, parsing, and writing cache.
# Using tempfile by default, it takes < 0.01s starting from the second time.
# You can specify not using tempfile, and it will take < 1s to run, including fetching and parsing:
ua = user_agent(use_tempfile=False)
# If there is an async function needing a useragent in your script,
# don't put `user_agent()` in your async function, put it above instead.
# Remove tempfile in a python script.
# May need `sudo python yourscript.py` for Linux.
from fake_user_agent import rm_tempfile
rm_tempfile()
Other usages on terminal
# Set to get a useragent in debug mode
fakeua <browser or omit> --debug
# Set to get a useragent without local caching
fakeua <browser or omit> --nocache
# Remove cache from tempfile folder
fakeua --remove
# Print the current version of the program
fakeua --version
Installation
pip install fake_user_agent
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fake_user_agent-2.1.5.tar.gz
.
File metadata
- Download URL: fake_user_agent-2.1.5.tar.gz
- Upload date:
- Size: 84.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd97d27e1004e7493ce2bb02a6d2c6a3c068cd7e503ae4cf58790cd4bffba2a0 |
|
MD5 | 273aa23d3183207acc9ee83fa429efc0 |
|
BLAKE2b-256 | 594dda3f985f9321edc4246b3ea31c43a6a8b1cae7b0c36b3650a5a29c6c9fe6 |
File details
Details for the file fake_user_agent-2.1.5-py3-none-any.whl
.
File metadata
- Download URL: fake_user_agent-2.1.5-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3c0df21bdf9ee4b1bf0e7801a381c109ca99e382dee6a53a51890ee79ae5f8e |
|
MD5 | 405f028464d0d424e1bfbbe11a9ade44 |
|
BLAKE2b-256 | c26197fdf0dada92e6b539ad02585c0c8b48bd35fa487f772791fc9cd16754a3 |