我的编程空间,编程开发者的网络收藏夹
学习永远不晚

教你用python和php写一个随机user_agent,突破反爬,实现数据大量采集

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

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

教你用python和php写一个随机user_agent,突破反爬,实现数据大量采集

python生成一个随机的user_agent

# -*- coding: utf-8 -*-
import random
dd = {}
list1 = ['100.0.4896.20', '100.0.4896.60', '101.0.4951.15', '101.0.4951.41', '102.0.5005.27', '102.0.5005.61', '103.0.5060.134', '103.0.5060.24', '103.0.5060.53', '104.0.5112.20', '104.0.5112.29', '104.0.5112.79', '105.0.5195.19', '105.0.5195.52', '106.0.5249.21', '106.0.5249.61', '107.0.5304.18', '107.0.5304.62', '108.0.5359.22', '108.0.5359.71', '109.0.5414.25', '109.0.5414.74', '110.0.5481.30', '110.0.5481.77', '111.0.5563.19', '111.0.5563.41', '111.0.5563.64', '112.0.5615.28', '112.0.5615.49', '113.0.5672.24', '113.0.5672.63', '114.0.5735.16', '114.0.5735.90', '70.0.3538.16', '70.0.3538.67', '70.0.3538.97', '71.0.3578.137', '71.0.3578.30', '71.0.3578.33', '71.0.3578.80', '72.0.3626.69', '72.0.3626.7', '73.0.3683.20', '73.0.3683.68', '74.0.3729.6', '75.0.3770.140', '75.0.3770.8', '75.0.3770.90', '76.0.3809.12', '76.0.3809.126', '76.0.3809.25', '76.0.3809.68', '77.0.3865.10', '77.0.3865.40', '78.0.3904.105', '78.0.3904.11', '78.0.3904.70', '79.0.3945.16', '79.0.3945.36', '80.0.3987.106', '80.0.3987.16', '81.0.4044.138', '81.0.4044.20', '81.0.4044.69', '83.0.4103.14', '83.0.4103.39', '84.0.4147.30', '85.0.4183.38', '85.0.4183.83', '85.0.4183.87', '86.0.4240.22', '87.0.4280.20', '87.0.4280.87', '87.0.4280.88', '88.0.4324.27', '88.0.4324.96', '89.0.4389.23', '90.0.4430.24', '91.0.4472.101', '91.0.4472.19', '92.0.4515.107', '92.0.4515.43', '93.0.4577.15', '93.0.4577.63', '94.0.4606.113', '94.0.4606.41', '94.0.4606.61', '95.0.4638.10', '95.0.4638.17', '95.0.4638.54', '95.0.4638.69', '96.0.4664.18', '96.0.4664.35', '96.0.4664.45', '97.0.4692.20', '97.0.4692.36', '97.0.4692.71', '98.0.4758.102', '98.0.4758.48', '98.0.4758.80', '99.0.4844.17', '99.0.4844.35', '99.0.4844.51']
version_list = ['32','64']
version = random.choice(version_list)

dd['user_agent'] = f'Mozilla/5.0 (Windows NT {random.choice(["10.0","7.0","8.0"])}; Win{version}; x{version}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{random.choice(list1)} Safari/537.36'

php 生成一个随机的user_agent

$agent_list = ['100.0.4896.20', '100.0.4896.60', '101.0.4951.15', '101.0.4951.41', '102.0.5005.27', '102.0.5005.61', '103.0.5060.134', '103.0.5060.24', '103.0.5060.53', '104.0.5112.20', '104.0.5112.29', '104.0.5112.79', '105.0.5195.19', '105.0.5195.52', '106.0.5249.21', '106.0.5249.61', '107.0.5304.18', '107.0.5304.62', '108.0.5359.22', '108.0.5359.71', '109.0.5414.25', '109.0.5414.74', '110.0.5481.30', '110.0.5481.77', '111.0.5563.19', '111.0.5563.41', '111.0.5563.64', '112.0.5615.28', '112.0.5615.49', '113.0.5672.24', '113.0.5672.63', '114.0.5735.16', '114.0.5735.90', '70.0.3538.16', '70.0.3538.67', '70.0.3538.97', '71.0.3578.137', '71.0.3578.30', '71.0.3578.33', '71.0.3578.80', '72.0.3626.69', '72.0.3626.7', '73.0.3683.20', '73.0.3683.68', '74.0.3729.6', '75.0.3770.140', '75.0.3770.8', '75.0.3770.90', '76.0.3809.12', '76.0.3809.126', '76.0.3809.25', '76.0.3809.68', '77.0.3865.10', '77.0.3865.40', '78.0.3904.105', '78.0.3904.11', '78.0.3904.70', '79.0.3945.16', '79.0.3945.36', '80.0.3987.106', '80.0.3987.16', '81.0.4044.138', '81.0.4044.20', '81.0.4044.69', '83.0.4103.14', '83.0.4103.39', '84.0.4147.30', '85.0.4183.38', '85.0.4183.83', '85.0.4183.87', '86.0.4240.22', '87.0.4280.20', '87.0.4280.87', '87.0.4280.88', '88.0.4324.27', '88.0.4324.96', '89.0.4389.23', '90.0.4430.24', '91.0.4472.101', '91.0.4472.19', '92.0.4515.107', '92.0.4515.43', '93.0.4577.15', '93.0.4577.63', '94.0.4606.113', '94.0.4606.41', '94.0.4606.61', '95.0.4638.10', '95.0.4638.17', '95.0.4638.54', '95.0.4638.69', '96.0.4664.18', '96.0.4664.35', '96.0.4664.45', '97.0.4692.20',
 '97.0.4692.36', '97.0.4692.71', '98.0.4758.102', '98.0.4758.48', '98.0.4758.80', '99.0.4844.17', '99.0.4844.35', '99.0.4844.51'];

$agent_list_rnd_v = $agent_list[array_rand($agent_list)];
$version_list = ['32','64'];
$version_list_rnd_v = $version_list[array_rand($version_list)];

$win_list = ["10.0","7.0","8.0"];
$win_list_rnd_v=$win_list[array_rand($win_list)];
$user_agent = "Mozilla/5.0 (Windows NT {$win_list_rnd_v}; Win{$version_list_rnd_v}; x{$version_list_rnd_v}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{$agent_list_rnd_v} Safari/537.36" ;


print_r($user_agent);

来源地址:https://blog.csdn.net/peihuwang/article/details/131110348

免责声明:

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

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

教你用python和php写一个随机user_agent,突破反爬,实现数据大量采集

下载Word文档到电脑,方便收藏和打印~

下载Word文档

编程热搜

  • Python 学习之路 - Python
    一、安装Python34Windows在Python官网(https://www.python.org/downloads/)下载安装包并安装。Python的默认安装路径是:C:\Python34配置环境变量:【右键计算机】--》【属性】-
    Python 学习之路 - Python
  • chatgpt的中文全称是什么
    chatgpt的中文全称是生成型预训练变换模型。ChatGPT是什么ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类完成一系列
    chatgpt的中文全称是什么
  • C/C++中extern函数使用详解
  • C/C++可变参数的使用
    可变参数的使用方法远远不止以下几种,不过在C,C++中使用可变参数时要小心,在使用printf()等函数时传入的参数个数一定不能比前面的格式化字符串中的’%’符号个数少,否则会产生访问越界,运气不好的话还会导致程序崩溃
    C/C++可变参数的使用
  • css样式文件该放在哪里
  • php中数组下标必须是连续的吗
  • Python 3 教程
    Python 3 教程 Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。 Python
    Python 3 教程
  • Python pip包管理
    一、前言    在Python中, 安装第三方模块是通过 setuptools 这个工具完成的。 Python有两个封装了 setuptools的包管理工具: easy_install  和  pip , 目前官方推荐使用 pip。    
    Python pip包管理
  • ubuntu如何重新编译内核
  • 改善Java代码之慎用java动态编译

目录