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

Uploaded Source

Built Distribution

fake_user_agent-0.0.8-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fake_user_agent-0.0.8.tar.gz
Algorithm Hash digest
SHA256 aa286cfb5b76a23a5e4395d1da72f0a354cbd2b0b127f3a36a205e006b27cc17
MD5 05089e648aaf2534046004306a58174c
BLAKE2b-256 7970dadc48d77b1f8d6ac75eeae08b785c5b4cf5760a9060f41ec09fa547cbe0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fake_user_agent-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 693728acf2739a116446c3311e9888159367a8417616fa74d3fb73f09237887c
MD5 969387895503e7e42c2808fa2535c244
BLAKE2b-256 824c61174819784061415d3447961d801317410682d3e385ab6d331068418c79

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