当前位置: 首页 > 工具软件 > FAKE > 使用案例 >

python fake_useragent

庞安晏
2023-12-01
Useragent:
(fake-useragent库可以随机得到一个UserAgent)
安装: pip install fake-useragent

使用:
from fake_useragent import UserAgent
ua = UserAgent()
ua.ie 随机得到一个ie的User Agent
ua.firefox
ua.chrome

ua.random 随机一个UserAgent

例:
>>> from fake_useragent import UserAgent
>>> ua=UserAgent()
>>> ua.ie
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; InfoPath.3; MS-RTC LM 8; .NET4.0C; .NET4.0E)'
>>> ua.ie
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.1; SV1; .NET CLR 2.8.52393; WOW64; en-US)'
>>> ua.firefox
'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0'
>>> ua.firefox
'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0'
>>> ua.random
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36'
>>> ua.random
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36'
>>>
 类似资料:

相关阅读

相关文章

相关问答