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

Usage

On your terminal, just simply enter fakeua

In your python script, just 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 based on my 200M bandwith, 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


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.0.6.tar.gz (145.1 kB view details)

Uploaded Source

Built Distribution

fake_user_agent-2.0.6-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fake_user_agent-2.0.6.tar.gz
Algorithm Hash digest
SHA256 ad19f4251a77324e2a9ca74050420f787f6bde242880ef29cf53f17f20b2dec9
MD5 0fd8d364b7963e9187c5b3f0ebe9075b
BLAKE2b-256 a056c60db31b52e7c4bc0cb217b879a6aaeffbb74c3fddf6e09396777ffb4ffa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fake_user_agent-2.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6170079ab3c0effed9b7cb80c11f50234f06c905f95ebdb28402db14cfeeac0e
MD5 a0a613fc068a030197f022ff8e5b71d6
BLAKE2b-256 6a6a3ab33bc26aa8ea1acfb299ed512041d7ffb20e9bb1f37c68b63bba64cbc3

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