"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
将他们放到列表里,然后import random ,使用random.choice(list)随机获取一个user-agent.
from fake_useragent import UserAgent
#调用
ua = UserAgent()
headers = {'User-Agent':ua.random}
print(headers)