Skip to main content

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 and aiohttp 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").

It takes less than 2s for the first run, including fetching, parsing, and writing cache.

It will take less than 0.01s starting from the second time by using cache by default.

Usage

As a binary

On your terminal, just simply enter fakeua

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 $HOME/.cache/fakeua folder
fakeua --remove  

# Print the current version of the program
fakeua --version

As a library

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")

# Specify not using cache, it will take < 1s to run, including fetching and parsing.
ua = user_agent(use_cache=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 cache in a python script. 
# May need `sudo python yourscript.py` for Linux.
from fake_user_agent import rm_cache
rm_cache()  

Installation

pip install fake_user_agent

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fake_user_agent-2.1.7.tar.gz (96.3 kB view details)

Uploaded Source

Built Distribution

fake_user_agent-2.1.7-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file fake_user_agent-2.1.7.tar.gz.

File metadata

  • Download URL: fake_user_agent-2.1.7.tar.gz
  • Upload date:
  • Size: 96.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for fake_user_agent-2.1.7.tar.gz
Algorithm Hash digest
SHA256 517283df4da9b19fcbca2a20e6fe91be7ff6b3c1fe26eb97d483bc97f9b12eb1
MD5 c0d69e3009b7b435d0cdde97ce8764b3
BLAKE2b-256 0221e2f14b50a58282395ee7ef86efe1f560da1a3adfe146d0df474c072e116b

See more details on using hashes here.

File details

Details for the file fake_user_agent-2.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for fake_user_agent-2.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2e74d8bf7ccd05eadccfda701df9b061bbde168cab4134527d1d049be72474c7
MD5 052b11125383f4bc46cd1ad3321e0164
BLAKE2b-256 feb2013b705b3542cefa1253308dc0520e9921932f382d7c002a9b4b74c28edd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page