当前位置: 移动技术网 > IT编程>脚本编程>Python > 反爬中设置随机代理

反爬中设置随机代理

2019年07月31日  | 移动技术网IT编程  | 我要评论

钱庆法,穿越大唐之天香国师,谢百三出生年月

反爬中有一个使用随机代理的

 

 

# 导入随机函数模块
import random

# 构建 user_agent 集合代理
user_agent = [
    'mozilla/4.0 (compatible; msie 7.0; windows nt 6.0; trident/4.0)',
    'mozilla/5.0 (windows nt 6.1; wow64; rv:34.0) gecko/20100101 firefox/34.0',
    'mozilla/5.0 (windows; u; windows nt 5.2) applewebkit/525.13 (khtml, like gecko) version/3.1 safari/525.13',
    'mozilla/4.0 (compatible; msie 8.0; windows nt 6.0; trident/4.0)',
    'mozilla/4.0 (compatible; msie 8.0; windows nt 6.1; win64; x64; trident/4.0)'
]

# 在headers 里生成随机代理
headers = {
    'user-agent' : random.choice(user_agent)
}

print(headers)

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网