Python实现手机号自动判断男女性别(实例解析)

yipeiwu_com5年前Python基础

本文性别判断主要依靠airtest中的自动化测试实现

通过自动对比支付宝页面男女图像,从而实现男女判断

代码如下:

男女判断函数:

// An highlighted block
def numbe():
  if exists(Template(r"tpl1574867500094.png", threshold=0.85, rgb=True, target_pos=0, record_pos=(0.779, 0.382), resolution=(960, 540))):
    sex = "女"   
  if exists(Template(r"tpl1574924960910.png", threshold=0.89, rgb=True, target_pos=5, record_pos=(0.779, 0.382), resolution=(960, 540))):
    sex = "男"
  else:
    sex = "不存在"
  namesex = sex
  keyevent("4")
  return namesex

手机滑动(根据手机分辨率自行调整):

// An highlighted block
def scoll():
  try:
    swipe(v1=(629, 1750),v2=(629, 310)) # 滑动距离需要根据手机分辨率自行调整        
  except:
    print("can't go back to the main page")

刷选函数:

// An highlighted block
def number():  
  data_list =[]
  for i in range(9): # 根据手机分辨率自行调整
    try:
      title =poco(name="com.alipay.mobile.contactsapp:id/contact_item_name")[i].get_text()
      name = poco(name="com.alipay.mobile.contactsapp:id/concast_from")[i].get_text()
      print(title)
      name_a =name[5:6]
      if title not in data_list and name_a is not "1":
        poco("com.alipay.mobile.contactsapp:id/contact_item_name")[i].click()       
        sexname=numbe()      
        if sexname =="男":
          print(str(sexname))
      
        else:
          print(str(sexname))
          
      else:
        print(name_a)
        print("不存在")
    except:
      print("出错,跳过!")

综合:

// An highlighted block
# -*- encoding=utf8 -*-
__author__ = "liuqingsong"
def numbe():
  if exists(Template(r"tpl1574867500094.png", threshold=0.85, rgb=True, target_pos=0, record_pos=(0.779, 0.382), resolution=(960, 540))):
    sex = "女"   
  if exists(Template(r"tpl1574924960910.png", threshold=0.89, rgb=True, target_pos=5, record_pos=(0.779, 0.382), resolution=(960, 540))):
    sex = "男"
  else:
    sex = "不存在"
  namesex = sex
  keyevent("4")
  return namesex
def scoll():
  try:
    swipe(v1=(629, 1750),v2=(629, 310)) # 滑动距离需要根据手机分辨率自行调整        
  except:
    print("can't go back to the main page")

def number():  
  data_list =[]
  for i in range(9): # 根据手机分辨率自行调整
    try:
      title =poco(name="com.alipay.mobile.contactsapp:id/contact_item_name")[i].get_text()
      name = poco(name="com.alipay.mobile.contactsapp:id/concast_from")[i].get_text()
      print(title)
      name_a =name[5:6]
      if title not in data_list and name_a is not "1":
        poco("com.alipay.mobile.contactsapp:id/contact_item_name")[i].click()       
        sexname=numbe()      
        if sexname =="男":
          print(str(sexname))
          with open(r'./new/男.csv','a',encoding='utf-8') as f:
            f.write("{},{}\n".format(title,sexname))
        else:
          print(str(sexname))
          with open(r'./new/女.csv','a',encoding='utf-8') as f:
            f.write("{},{}\n".format(title,sexname))
      else:
        print(name_a)
        print("不存在")
    except:
      print("出错,跳过!")
a=0
while a<5:#根据手机上号码量的多少自行选择
  number()
  scoll()
  sleep(1)
  a=a+1

以上是用的是airtest实现的,效率不是很高,同样进行简单改动可以实现支付宝真实号码筛选,效率很高,偶尔使用一下还是可以的,切不可用于非法用途,大家有什么好的方式欢迎留言!

总结

以上所述是小编给大家介绍的Python实现手机号自动判断男女性别,希望对大家有所帮助!

相关文章

Python获取昨天、今天、明天开始、结束时间戳的方法

如下所示: #!/usr/bin/python # coding=utf-8 # import time import datetime # 今天日期 today = datetim...

eclipse创建python项目步骤详解

eclipse创建python项目步骤详解

eclipse安装Python插件之后,主要是为了方便Python代码就可以再Eclipse进行代码脚本,使用Eclipse开发Python脚本,主要写代码会有提示功能,提高写代码效率,...

Python实现在某个数组中查找一个值的算法示例

第一种算法思路: 第一步:随机出来一个数组的下标 第二步:判断下标对应的值是否等于被查找的值,是的话终止,已找到,否的话转第三步。 第三步:判断是否随机完数组的所有下标,是的话终止,没找...

Python3结合Dlib实现人脸识别和剪切

Python3结合Dlib实现人脸识别和剪切

0.引言 利用python开发,借助Dlib库进行人脸识别,然后将检测到的人脸剪切下来,依次排序显示在新的图像上; 实现的效果如下图所示,将图1原图中的6张人脸检测出来,然后剪切下来,...

python判断计算机是否有网络连接的实例

先安装第三方库:pip install requests def isConnected(): import requests try: html = request...