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

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fake_user_agent-0.0.13.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.13.tar.gz
Algorithm Hash digest
SHA256 ed7249413a64b3a94bf6a174865728b7acbddd322b091d26b58714789a2ba445
MD5 fb1483b600b3ec9aeb02b3d3c41b5093
BLAKE2b-256 406f705887a94a66fd167b6a2e8eaea8fb07a7f49753318059c44df11a8707ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fake_user_agent-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 8aa86dc3d0960c5acc0a8fe5a5afc64a9d173f68c21c34a8831f8ab0693dcb67
MD5 0d1cc0cf8ccf35a5f7df122eca301179
BLAKE2b-256 37270a11dac4fb6e5989d76ceab2394568ab61cd4605ae9b5ec93b06f4079e5d

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