python 自动生成useragent/User-Agent方法全解析
发布时间:2020-05-30 18:46:28 所属栏目:Python 来源:互联网
导读:python 自动生成useragent/User-Agent方法全解析
|
在工作中进行爬虫时,经常会需要提供User-Agent,如果不提供User-Agent,会导致爬虫在请求网页时,请求失败,所以需要大量User-Agent。如何生成合法的User-Agent? 使用fake-useragent库就可以解决该问题。 安装: pipinstallfake-useragent 使用: 该模块使用非常简单。 fromfake_useragentimportUserAgent ua=UserAgent() ua.ie #Mozilla/5.0(Windows;U;MSIE9.0;WindowsNT9.0;en-US); ua.msie #Mozilla/5.0(compatible;MSIE10.0;Macintosh;IntelMacOSX10_7_3;Trident/6.0)' ua['InternetExplorer'] #Mozilla/5.0(compatible;MSIE8.0;WindowsNT6.1;Trident/4.0;GTB7.4;InfoPath.2;SV1;.NETCLR3.3.69573;WOW64;en-US) ua.opera #Opera/9.80(X11;Linuxi686;U;ru)Presto/2.8.131Version/11.11 ua.chrome #Mozilla/5.0(WindowsNT6.1)AppleWebKit/537.2(KHTML,likeGecko)Chrome/22.0.1216.0Safari/537.2' ua.google #Mozilla/5.0(Macintosh;IntelMacOSX10_7_4)AppleWebKit/537.13(KHTML,likeGecko)Chrome/24.0.1290.1Safari/537.13 ua['googlechrome'] #Mozilla/5.0(X11;CrOSi6862268.111.0)AppleWebKit/536.11(KHTML,likeGecko)Chrome/20.0.1132.57Safari/536.11 ua.firefox #Mozilla/5.0(WindowsNT6.2;Win64;x64;rv:16.0.1)Gecko/20121011Firefox/16.0.1 ua.ff #Mozilla/5.0(X11;Ubuntu;Linuxi686;rv:15.0)Gecko/20100101Firefox/15.0.1 ua.safari #Mozilla/5.0(iPad;CPUOS6_0likeMacOSX)AppleWebKit/536.26(KHTML,likeGecko)Version/6.0Mobile/10A5355dSafari/8536.25 #最好的,通过真实世界的浏览器使用统计随机 ua.random (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
