手机号空号批量检测接口

# coding=gbk
import requests
# 定义要使用的 API 地址和参数
url = "http://api.kazhiguo.com/api/mobileempty/"
api_key = "你的APIKEY"

# 打开文件,将文件中的手机号逐行读取到列表中
with open("phone1.txt") as file:
    phone_numbers = file.readlines()

# 遍历手机号列表,发送请求并将结果写入不同的文件
with open("empty.txt", "w") as empty_file, open("another.txt", "w") as another_file, open("error.txt", "w") as error_file:
    for phone in phone_numbers:
        # 清除手机号中的空白字符
        phone = phone.strip()

        # 如果手机号为空,则写入 empty.txt 文件中
        if not phone:
            empty_file.write(phone + "\n")
        else:
            # 更新请求参数中的手机号和 APIKEY
            params = {"apikey": api_key, "mobile": phone}

            # 发送请求
            response = requests.get(url, params=params)

            # 解析返回的 JSON 数据
            json_data = response.json()

            # 根据返回值将手机号写入不同的文件
            if json_data["code"] == 200:
                if json_data["result"]["status"] == 0:
                    empty_file.write(phone + "\n")
                else:
                    another_file.write(phone + "\n")
            else:
                error_file.write(phone +"/" +json_data["code"] + "/"+ json_data["error_code"])
#another.txt为非空号
#empty.txt为空号
#返回码不是200则将错误代码输出到error.txt

逐行读取phone1.txt内的手机号

将空号输出到 empty.txt,将非空号输入到 not_empty.txt,如果返回值不是200将错误信息输入到 error.txt

第二版:

# coding=gbk
import requests
# 定义要使用的 API 地址和参数
url = "http://api.kazhiguo.com/api/mobileempty/"
api_key = "你的APIKEY" #请手动更改

# 打开文件,将文件中的手机号逐行读取到列表中
with open("resultphone.txt") as file:
    phone_numbers = file.readlines()

# 遍历手机号列表,发送请求并将结果写入不同的文件
with open("empty.txt", "w") as empty_file, open("another.txt", "w") as another_file, open("error.txt", "w") as error_file, \
        open("空号.txt", "w") as konghao_file, open("实号.txt", "w") as shihao_file, open("停机.txt", "w") as tingji_file, open("库无.txt", "w") as kuwu_file, open("沉默号.txt", "w") as chenmohao_file, open("风险号.txt", "w") as fengxianhao_file, open("其他.txt", "w") as qita_file:
    for phone in phone_numbers:
        # 清除手机号中的空白字符
        phone = phone.strip()

        # 如果手机号为空,则写入 empty.txt 文件中
        if not phone:
            empty_file.write(phone + "\n")
        else:
            # 更新请求参数中的手机号和 APIKEY
            params = {"apikey": api_key, "mobile": phone}

            # 发送请求
            response = requests.get(url, params=params)

            # 解析返回的 JSON 数据
            json_data = response.json()

            # 根据返回值将手机号写入不同的文件
            if json_data["code"] == 200:
                if json_data["result"]["status"] == 0:
                    empty_file.write(phone + "\n")
                else:
                    another_file.write(phone + "\n")
            else:
                error_file.write(phone +"/" +json_data["code"] + "/"+ json_data["error_code"])


            if json_data["code"] == 200:
                if json_data["result"]["status"] == 0:
                    konghao_file.write(phone + "\n")
                if json_data["result"]["status"] == 1:
                    shihao_file.write(phone + "\n")
                if json_data["result"]["status"] == 2:
                    tingji_file.write(phone + "\n")
                if json_data["result"]["status"] == 3:
                    kuwu_file.write(phone + "\n")
                if json_data["result"]["status"] == 4:
                    chenmohao_file.write(phone + "\n")
                if json_data["result"]["status"] == 5:
                    fengxianhao_file.write(phone + "\n")
                else:
                    qita_file.write(phone + "\n")
            else:
                pass

#another.txt为非空号
#empty.txt为空号
#中文为号段分类
#返回码不是200则将错误代码输出到error.txt

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值