Skip to main content

Fake useragent randomly generates a useragent for fetching a webpage 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 is randomly chosen, so each time the 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")

# Using tempfile takes less than 0.001s from the second time.
# Not using it takes less than 3s because of fetching data on the web each time.
# By default tempfile is used, you can turn it off by:
ua = user_agent(use_temfile=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.


# You can also import multithreading version offered.
# Time taken is no big difference with the default asyncio version.
# All usages are same, except that `user_agent()` can be put within an async function.
from fake_user_agent.thread_version import user_agent


# Remove tempfile
rm_tempfile()

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

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

Installation

pip3 install fake_user_agent
sudo pip3 install fake_user_agent # For Linux

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

Uploaded Source

Built Distribution

fake_user_agent-0.0.14-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fake_user_agent-0.0.14.tar.gz
Algorithm Hash digest
SHA256 86ade990010325a1e4e7a0486e64166ab345eec76c3beeb027846aa50d1e7c1b
MD5 bc25d34be1f428b8325ae21a48368d33
BLAKE2b-256 36044a2fe019154ed062288b4aee274fac3c3f843a1d8e45ee3fedecff6d9172

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fake_user_agent-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 d696e0e076110b7339d34002bf2726d6737deca1046ea2d4b55ba828a19e220c
MD5 3af60a6f9ab01f21b7013132f184f42b
BLAKE2b-256 ff3fa295fe3f75fbe059bb85cadca2ebbe27176d44ed458907925dd32a674c61

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