爬虫-UserAgent

废话不多说,直接写代码

[root@localhost ~]# pip3 install fake-useragent
Collecting fake-useragent
  Downloading https://files.pythonhosted.org/packages/19/78/942c4be64409dcb3ebdd5741e1b6cd
c4d6153b16e9765bcecfb81547c7a1/fake-useragent-0.1.10.tar.gzInstalling collected packages: fake-useragent
  Running setup.py install for fake-useragent ... done
Successfully installed fake-useragent-0.1.10
>>> from fake_useragent import UserAgent
>>> ua = UserAgent()
>>> ua.random
'Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko)
 Version/5.0.4 Safari/533.20.27'

>>> ua.random 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.15 99.17 Safari/537.36'>>>

可以自动生成UserAgent,伪造浏览器

原文地址:https://www.cnblogs.com/52-qq/p/9559862.html