美文网首页
python添加代理反爬虫策略

python添加代理反爬虫策略

作者: Do_More | 来源:发表于2017-10-23 16:52 被阅读0次
    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()
    

    相关文章

      网友评论

          本文标题:python添加代理反爬虫策略

          本文链接:https://www.haomeiwen.com/subject/bsmauxtx.html