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
andaiohttp
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fake_user_agent-0.0.9.tar.gz
.
File metadata
- Download URL: fake_user_agent-0.0.9.tar.gz
- Upload date:
- Size: 52.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40bc12e087e5ab1bf66bc142194f4f475eac7446ebd07c4710af55351789aae8 |
|
MD5 | f5b731837b545fbb9faa59ad50e4de56 |
|
BLAKE2b-256 | 1ad14549fa40bda4ea50a1efac58f746aa4b426b52bad2c15fe1d74b5d991cfe |
File details
Details for the file fake_user_agent-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: fake_user_agent-0.0.9-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8773af2710aa3589e6fcbf68639e2aa0b472eae50c3282d020f623f15673888b |
|
MD5 | 0ef9d604a576e1b6c73705eac1624b24 |
|
BLAKE2b-256 | a76346c0cb24d36d2739343e935f4e487cb66e5102bae9a9d87de62bcf6155c6 |