文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

随机生成UserAgent的python

2023-01-31 02:39

关注

一、安装fake-useragent库:
pip install fake-useragent

二、使用方法:
1、导入fake-useragent库
from fake_useragent import UserAgent

2、实例化一个对象
ua = UserAgent()

3、随机生成IE浏览器的UserAgent

ua.ie
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/4.0; GTB7.4; InfoPa
th.3; SV1; .NET CLR 3.1.76908; WOW64; en-US)'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .N
ET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; S
LCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba U
NTRUSTED/1.0'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; InfoPath.2; S
V1; .NET CLR 2.0.50727; WOW64)'
ua.ie
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0'

4、随机生成firefox浏览器的UserAgent

ua.firefox
u'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0'
ua.firefox
u'Mozilla/5.0 (Windows NT 5.0; rv:21.0) Gecko/20100101 Firefox/21.0'
ua.firefox
u'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'
ua.firefox
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0'
ua.firefox
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'

5、随机生成chrome浏览器的UserAgent

ua.chrome
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/27.0.1453.93 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/35.0.1916.47 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40
.0.2214.93 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/41.0.2225.0 Safari/537.36'
ua.chrome
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like
Gecko) Chrome/24.0.1309.0 Safari/537.17'

6、随机生成safari浏览器的UserAgent

ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 6.1; de-DE) AppleWebKit/533.20.25 (KHTML,
like Gecko) Version/5.0.3 Safari/533.19.4'
ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 6.1; ja-JP) AppleWebKit/533.20.25 (KHTML,
like Gecko) Version/5.0.3 Safari/533.19.4'
ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 6.1; sv-SE) AppleWebKit/533.19.4 (KHTML, l
ike Gecko) Version/5.0.3 Safari/533.19.4'
ua.safari
u'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU) AppleWebKit/533.18.1 (KHTML, l
ike Gecko) Version/5.0.2 Safari/533.18.5'

7、随机生成google浏览器的UserAgent

ua.google
u'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.
0.2224.3 Safari/537.36'
ua.google
u'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.
0.1453.93 Safari/537.36'
ua.google
u'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/41.0.2226.0 Safari/537.36'
ua.google
u'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.
0.3319.102 Safari/537.36'

8、随机生成opera浏览器的UserAgent

ua.opera
u'Mozilla/5.0 (Windows NT 6.1; U; de; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 O
pera 11.01'
ua.opera
u'Opera/9.80 (Windows NT 6.1; Opera Tablet/15165; U; en) Presto/2.8.149 Version/
11.1'
ua.opera
u'Opera/9.80 (Windows NT 6.1; U; sv) Presto/2.7.62 Version/11.01'
ua.opera
u'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51'
ua.opera
u'Opera/9.80 (Windows NT 6.1; U; pl) Presto/2.7.62 Version/11.00'

9、随机生成各种浏览器的UserAgent

ua.random
u'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/27.0.1453.93 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/30.0.1599.17 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/30.0.1599.17 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chr
ome/41.0.2225.0 Safari/537.36'
ua.random
u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/32.0.1664.3 Safari/537.36'
ua.random
u'Mozilla/5.0 (X11; CrOS i686 4319.74.0) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/29.0.1547.57 Safari/537.36'
ua.random
u'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko
) Chrome/32.0.1667.0 Safari/537.36'
ua.random
u'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0'
ua.random
u'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40
.0.2214.93 Safari/537.36'
ua.random
u'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2;
.NET CLR 2.0.50727; InfoPath.3; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR
3.0.30729; MS-RTC LM 8)'

三、查看fake-useragent版本
1、使用pip list命令查看fake-useragent版本
(scrapytest) F:\python-virtualenv\scrapytest\Scripts>pip list
attrs (17.3.0)
Automat (0.6.0)
certifi (2017.11.5)
cffi (1.11.2)
chardet (3.0.4)
constantly (15.1.0)
cryptography (2.1.3)
cssselect (1.0.1)
enum34 (1.1.6)
fake-useragent (0.1.8)
hyperlink (17.3.1)
idna (2.6)

访问https://fake-useragent.herokuapp.com/browsers/0.1.8查看useragent库

四、user-agent库
https://fake-useragent.herokuapp.com/browsers/0.1.4

json格式显示的,可以把内容复制到以下网址进行json视图显示
https://www.bejson.com/jsonviewernew/

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯