[819]python随机获取请求头

安装包

pip install fake_useragent
pip install faker

用法

# -*- coding:utf-8 -*-

# #可以随机获取一个user-agent头
from fake_useragent import UserAgent #pip install fake_useragent

ua = UserAgent()
user_agent=ua.random
print(user_agent)


# #使用Faker库随机生成虚假header
from faker import Faker #pip install faker

fake = Faker()
headers ={'User-Agent':fake.user_agent()}
print(headers)

你可能感兴趣的:(python前行者)