这是一个本地版ua随机头, 不会出现请求超时等错误, 功能单一, 使用简单
fake_useragent 是一个非常好用的随机请求头模块
但因为这个模块在本地运行总是会因为各种各样的原因, 报错
所以重新整理fake_useragent模块的所有请求头, 实现在本地获取随机请求头
实际上就是把所有的请求头保存到本地 😂
更多精彩文章, 请关注 [ 不止于python ] 公众号
安装方法
pip3.7 install local-fake-useragent
使用方法
from local_fake_useragent import UserAgent
# 获取所有浏览器的随机请求头
u = UserAgent()
# 获取chrome的随机请求头
u = UserAgent("chrome")
# 添加自定义请求头
c = {
"0": ["a", "b"]
}
u = UserAgent("0", add_custom_header=c)
print(u.rget)
# 支持的浏览器
print(UserAgent.BROWER)
测试用例
import requests
from local_fake_useragent import UserAgent
uas = UserAgent()
headers = {'User-agent': uas.rget}
url = 'https://www.baidu.com'
response = requests.get(url=url, headers=headers)
response.encoding = response.apparent_encoding
print(response.text)
Metadata
Release files for local-fake-useragent 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| local_fake_useragent-2.0.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Release files / local_fake_useragent-2.0.1-py2.py3-none-any.whl
| Download URL | local_fake_useragent-2.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 326.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
35f1a3a84dd58f476749d78b3d4090152f6baf9c9e9455428ad0cbf349fe1af8
|
|
BLAKE2b-256 checksum How to use checksums |
dcc9d4e6e3eeb01aa0ce259595b98aff28151164cad01d39fee7d2c9892ad966
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.3
|
Security for local-fake-useragent 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.