useragent池

fake_useragent

from fake_useragent import UserAgent
fake_useragent :只有250个ua
安装:pip install fake_useragent

# 实力化
ua = UserAgent(verify_ssl=False)
参数:
use_cache_server=False # 禁用服务器缓存
cache=False  # 不缓存数据
verify_ssl=False  # 忽略ssl验证

# 对应浏览器的头部信息
# print(ua.ie)   # ie的user_agent
# print(ua.opera)  #opera浏览器
# print(ua.chrome)  # chrom浏览器
# print(ua.firefox)  # 火狐浏览器
# print(ua.safari) # safri浏览器

# # 随机返回头部信息,推荐使用
# print(ua.random)

user_agent = set()
for i in range(50):
  k = ua.safari
  user_agent.add(k)
print(user_agent)

最强ua池,1w个

import redis
import requests
from lxml import etree
url = "http://useragentstring.com/pages/useragentstring.php?typ=Browser"

header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60',
    }

response = requests.get(url,headers=header,timeout=60
                        )

tree = etree.HTML(response.text)
ua_list = tree.xpath('//div[@id="liste"]/ul/li/a/text()')

for ua in ua_list:
    if len(ua)>20:
        rds_16_8.sadd('user_agent_fuck', ua)

posted @ 2020-11-10 14:58  Jeff的技术栈  阅读(285)  评论(0编辑  收藏  举报
回顶部