python学习之二 代理ip有效性验证

python学习之二 代理ip有效性验证

验证代码Demo

# -*- coding: utf-8 -*-
import requests
def gitIp():
    ipList=[]
    with open("../../proxies.txt", "r") as f:
        ipList=f.read().split("\n")
        # print ipList
        # print "----------------------"
    return ipList


ipList=['https://39.88.13.3:53281',
        'https://182.43.203.43:4306',
        'https://183.62.71.242:3128',
        'https://61.160.208.222:8080',
        'https://123.179.28.159:8080',
        'https://58.56.90.202:53281',
        'https://222.88.144.119:53281',
        'https://61.158.111.142:53281',
        'https://139.224.24.26:8888',
        'https://124.232.148.7:3128',
        'https://218.15.23.229:53281',
        'https://222.34.139.52:808',
        'https://218.18.10.11:9797',
        'https://119.136.113.49:9797']
def valVer(proxys):
    badNum = 0
    goodNum = 0
    for proxy in proxys:
        try:
            proxy_host = proxy
            protocol = 'https' if 'https' in proxy_host else 'http'
            proxies = {protocol: proxy_host}
            response = requests.get('http://www.baidu.com', proxies=proxies, timeout=2)
            if response.status_code != 200:
                badNum += 1
                print proxy_host, 'bad proxy'
            else:
                goodNum += 1
                print proxy_host, 'success proxy'
        except Exception, e:
            print e
            # print proxy_host, 'bad proxy'
            badNum += 1
            continue
    print 'success proxy num : ', goodNum
    print 'bad proxy num : ', badNum

# valVer(gitIp())  #读取本地文件里的IP
valVer(ipList)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值