from fake_useragent import UserAgent

ua = UserAgent()
headers = {'User-Agent': ua.random}
print(ua.random)
是的 你没看错,就这两行代码就可以搞定了,但是这个是一个第三方库,我们需要用pip install fake_useragent  安装以后 直接就可以使用了 

我们看下输出的结果:

 

随机获取不一样的ua,小伙伴都可以试试,下一篇会写,如何让获取动态ip
--------------------- 
作者:ywj_486 
来源:CSDN 
原文:https://blog.csdn.net/ywj_486/article/details/84565074 
版权声明:本文为博主原创文章,转载请附上博文链接!

 

相关文章:

  • 2022-01-31
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-12-19
  • 2021-07-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2022-03-07
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案