Fake useragent randomly generates a useragent for fetching a web page 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
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 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")
# It usually takes < 2s for the first run, including the time for fetching and parsing.
# Using tempfile, it takes < 0.01s from the second time.
# By default, tempfile is used, it can be turned off and it will take < 2s to run:
ua = user_agent(use_tempfile=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.
# Remove tempfile in python script.
# May need sudo python yourscript.py for Linux
from fake_user_agent.main import rm_tempfile
rm_tempfile()
Remove tempfile on Linux or MacOS terminal. Replace var
with respective folder name on Windows
find /var/ -name "fake_useragent*" -type f -exec rm {} \; # For MacOS
find /tmp/ -name "fake_useragent*" -type f -exec rm {} \; # For Linux
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.1.2.tar.gz
.
File metadata
- Download URL: fake_user_agent-0.1.2.tar.gz
- Upload date:
- Size: 144.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0b504205bd8e9dfe859ef697a178060a9fa35ff77c7f40adc2d7b9986ddb53e |
|
MD5 | 13a513d99408a0ef5f1a53615fb50dc5 |
|
BLAKE2b-256 | 3e6d032112c824cc82571de70a8bccad5c322afb83bb7d47141a86afdffa85cd |
File details
Details for the file fake_user_agent-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: fake_user_agent-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aea28d4c66d23a36f6e167ab9e684e5d1aba77978972b6db5efab84687d7c28a |
|
MD5 | 09990bc08909a27b69032586a5fca39d |
|
BLAKE2b-256 | d4a223bb82abc8d2025a1e90d8af7db444e4b321622a424a2d88571eed52cc39 |