fake_useragent 模块为第三方模块。
还没安装的,要先安装。
pip install fake_useragent
from fake_useragent import UserAgent
RandomUser = UserAgent().random
IeUser = UserAgent().ie
FirefoxUser = UserAgent().firefox
ChromeUser = UserAgent().chrome
print(RandomUser) # 随机浏览器请求头
print(IeUser) # 随机IE浏览器请求头
print(FirefoxUser) # 随机Firefox浏览器请求头
print(ChromeUser) # 随机Chrome浏览器请求头
Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2117.157 Safari/537.36
Mozilla/4.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20130331 Firefox/21.0
Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36