随机生成ua的库

from fake_useragent import UserAgent
ua = UserAgent()
ua.ie
Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);
ua.chrome
Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)'
ua.opera
Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11
from faker import Faker
ua = Faker()
ua.user_agent()
Out[24]: 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_9_1; rv:1.9.2.20) Gecko/2016-12-13 00:29:52 Firefox/4.0'
ua.user_agent()
Out[25]: 'Mozilla/5.0 (Windows; U; Windows 98) AppleWebKit/531.46.5 (KHTML, like Gecko) Version/4.0 Safari/531.46.5'
ua.chrome()
Out[26]: 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/5362 (KHTML, like Gecko) Chrome/60.0.850.0 Safari/5362'

你可能感兴趣的:(爬虫)