Skip to main content

Random request headers for local versions of browsers

Project description

这是一个本地版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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

local_fake_useragent-2.0.1-py2.py3-none-any.whl (326.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file local_fake_useragent-2.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for local_fake_useragent-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 35f1a3a84dd58f476749d78b3d4090152f6baf9c9e9455428ad0cbf349fe1af8
MD5 04531bc5e372777e8218a83111a17c39
BLAKE2b-256 dcc9d4e6e3eeb01aa0ce259595b98aff28151164cad01d39fee7d2c9892ad966

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page