教你用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