当前位置:   article > 正文

手机号空号批量检测接口_批量空号检测

批量空号检测
  1. # coding=gbk
  2. import requests
  3. # 定义要使用的 API 地址和参数
  4. url = "http://api.kazhiguo.com/api/mobileempty/"
  5. api_key = "你的APIKEY"
  6. # 打开文件,将文件中的手机号逐行读取到列表中
  7. with open("phone1.txt") as file:
  8. phone_numbers = file.readlines()
  9. # 遍历手机号列表,发送请求并将结果写入不同的文件
  10. with open("empty.txt", "w") as empty_file, open("another.txt", "w") as another_file, open("error.txt", "w") as error_file:
  11. for phone in phone_numbers:
  12. # 清除手机号中的空白字符
  13. phone = phone.strip()
  14. # 如果手机号为空,则写入 empty.txt 文件中
  15. if not phone:
  16. empty_file.write(phone + "\n")
  17. else:
  18. # 更新请求参数中的手机号和 APIKEY
  19. params = {"apikey": api_key, "mobile": phone}
  20. # 发送请求
  21. response = requests.get(url, params=params)
  22. # 解析返回的 JSON 数据
  23. json_data = response.json()
  24. # 根据返回值将手机号写入不同的文件
  25. if json_data["code"] == 200:
  26. if json_data["result"]["status"] == 0:
  27. empty_file.write(phone + "\n")
  28. else:
  29. another_file.write(phone + "\n")
  30. else:
  31. error_file.write(phone +"/" +json_data["code"] + "/"+ json_data["error_code"])
  32. #another.txt为非空号
  33. #empty.txt为空号
  34. #返回码不是200则将错误代码输出到error.txt

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

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

第二版:

  1. # coding=gbk
  2. import requests
  3. # 定义要使用的 API 地址和参数
  4. url = "http://api.kazhiguo.com/api/mobileempty/"
  5. api_key = "你的APIKEY" #请手动更改
  6. # 打开文件,将文件中的手机号逐行读取到列表中
  7. with open("resultphone.txt") as file:
  8. phone_numbers = file.readlines()
  9. # 遍历手机号列表,发送请求并将结果写入不同的文件
  10. with open("empty.txt", "w") as empty_file, open("another.txt", "w") as another_file, open("error.txt", "w") as error_file, \
  11. 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:
  12. for phone in phone_numbers:
  13. # 清除手机号中的空白字符
  14. phone = phone.strip()
  15. # 如果手机号为空,则写入 empty.txt 文件中
  16. if not phone:
  17. empty_file.write(phone + "\n")
  18. else:
  19. # 更新请求参数中的手机号和 APIKEY
  20. params = {"apikey": api_key, "mobile": phone}
  21. # 发送请求
  22. response = requests.get(url, params=params)
  23. # 解析返回的 JSON 数据
  24. json_data = response.json()
  25. # 根据返回值将手机号写入不同的文件
  26. if json_data["code"] == 200:
  27. if json_data["result"]["status"] == 0:
  28. empty_file.write(phone + "\n")
  29. else:
  30. another_file.write(phone + "\n")
  31. else:
  32. error_file.write(phone +"/" +json_data["code"] + "/"+ json_data["error_code"])
  33. if json_data["code"] == 200:
  34. if json_data["result"]["status"] == 0:
  35. konghao_file.write(phone + "\n")
  36. if json_data["result"]["status"] == 1:
  37. shihao_file.write(phone + "\n")
  38. if json_data["result"]["status"] == 2:
  39. tingji_file.write(phone + "\n")
  40. if json_data["result"]["status"] == 3:
  41. kuwu_file.write(phone + "\n")
  42. if json_data["result"]["status"] == 4:
  43. chenmohao_file.write(phone + "\n")
  44. if json_data["result"]["status"] == 5:
  45. fengxianhao_file.write(phone + "\n")
  46. else:
  47. qita_file.write(phone + "\n")
  48. else:
  49. pass
  50. #another.txt为非空号
  51. #empty.txt为空号
  52. #中文为号段分类
  53. #返回码不是200则将错误代码输出到error.txt

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/894762
推荐阅读
相关标签
  

闽ICP备14008679号