Skip to main content

Fake useragent 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, enter fakeua

In python script, just import the function. Every time you run your python script, the user agent value is different.

from fake_user_agent.main import user_agent

# Not specify a browser:
ua = user_agent()

# Specify a browser to randomly choose from:
ua = user_agent("chrome")

# It usually takes less than 2s for the first run, including the time for fetching web and parsing html. 
# Using tempfile, it takes less than 0.01s from the second time.
# By default, tempfile is used, you can turn it off and it will take less than 2s each run:
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 python script. 
# May need sudo python yourscript.py for Linux
from fake_user_agent.main import rm_tempfile
rm_tempfile()  

Remove tempfile on Linux or MacOS terminal. Replace var with respective folder name on Windows

find /var/ -name "fake_useragent*" -type f -exec rm {} \; # For MacOS
find /tmp/ -name "fake_useragent*" -type f -exec rm {} \; # For Linux

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

Uploaded Source

Built Distribution

fake_user_agent-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fake_user_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2fc596d8538212bd1eac8861525af93eec4121f0a1bc99bca5d2b05b55648873
MD5 f0f8ff544a6a8b0afa3dd73f8d918986
BLAKE2b-256 b71bb268b5181fb793173dd69207f1c6e18036f57f78da2cd337f56276c86807

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fake_user_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c85717d919094cdc5a0228fa34be6689107a2b0b0e68f8e4b266245310228db
MD5 bf2b83942a2d06213b5b9977e247c0f2
BLAKE2b-256 26eb6ffdce128896f8993b53a21251701923849999337dd1d95fdcdf06a68a2b

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