python添加代理反爬虫策略

2017-10-23  本文已影响0人  Do_More
request = urllib2.Request(url)

ip_list=['119.6.136.122','114.106.77.14']
proxy_support = urllib2.ProxyHandler({'http':random.choice(ip_list)})
opener = urllib2.build_opener(proxy_support)  

request.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36')

urllib2.install_opener(opener) 

response = urllib2.urlopen(request,timeout=30)
downloadFileData = response.read()
上一篇下一篇

猜你喜欢

热点阅读