python 爬虫 UserAgent 随机生成 Python使用三方库 fake_useragent

1、安装 fake_useragent

pip install fake_useragent

2.示例代码

from fake_useragent import UserAgent

# 得到ua对象
ua = UserAgent()
#ie浏览器的user agent
print(ua.ie)

#opera浏览器
print(ua.opera)

#chrome浏览器
print(ua.chrome)

#firefox浏览器
print(ua.firefox)

#safri浏览器
print(ua.safari)

#最常用的方式
#写爬虫最实用的是可以随意变换headers,一定要有随机性。支持随机生成请求头
print(ua.random)

猜你喜欢

转载自blog.csdn.net/weixin_45598506/article/details/112907450