1 安装 fake_useragent
pip install fake_useragent
2 使用
# -*- coding:utf-8 -*- from fake_useragent import UserAgent import random ua = UserAgent() headers = {'User-Agent': ua.random}
3 使用随机谷歌UA
# -*- coding:utf-8 -*- from fake_useragent import UserAgent import random ua = UserAgent() headers = {'User-Agent': ua.chrome}
4 使用随机火狐UA
# -*- coding:utf-8 -*- from fake_useragent import UserAgent import random ua = UserAgent() headers = {'User-Agent': ua.firefox}