1 Star 0 Fork 1

liinux / IP_POOL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
_request.py 1012 Bytes
一键复制 编辑 原始数据 按行查看 历史
shimeng 提交于 2017-09-22 13:53 . 验证函数脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by shimeng on 17-9-20
"""
验证函数
若请求成功,则返回响应时间, ip
若错误, 则返回None, None, 请求框架将不对这一结果进行处理
"""
import requests
import urlparse
header = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'}
def valid(_args, dont_filter):
url = _args.get('url')
header['Host'] = urlparse.urlparse(url).netloc
time_out = _args.get('time_out')
_ip = _args.get('ip')
diy_header = _args.get('diy_header') if _args.get('diy_header') else header
try:
proxy = {
'http': 'http://%s' % _ip,
'https': 'http://%s' % _ip
}
con = requests.get(url, headers=diy_header, proxies=proxy, timeout=time_out)
except Exception,e:
# print e
return None, None
else:
if con.status_code == 200:
return con.elapsed.microseconds/1000000., _ip
Python
1
https://gitee.com/tigerxue/IP_POOL.git
git@gitee.com:tigerxue/IP_POOL.git
tigerxue
IP_POOL
IP_POOL
master

搜索帮助