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

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 {} \;

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

Uploaded Source

Built Distribution

fake_user_agent-0.0.10-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fake_user_agent-0.0.10.tar.gz
Algorithm Hash digest
SHA256 3bb179ac7085f10930eb69cc838f194c96cf36f4f09b15675329bad6fc8aa2cc
MD5 28c9266ff6fb0755d17e27e52032ef4c
BLAKE2b-256 6e0fd4e6571d26e969efe43dc4ca0710f33420c8ee2468f4dd69a628d446d0bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fake_user_agent-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 fabc90936765945de8d72d61422d25ca6c0bed589e4058c8a0143cefc2d17a0d
MD5 f15b11ad1c80b3c9a500d8e2f6db3507
BLAKE2b-256 7a3e73978475cee4d4cdbe43ac8771d32c8e01b3703b41429b401300a8774217

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