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实现随机生成有效手机号码及身份证功能示例

Python实现随机生成有效手机号码及身份证功能示例

本文实例讲述了Python实现随机生成有效手机号码及身份证功能。分享给大家供大家参考,具体如下: 中国那么大,人那么多,几乎人手一部手机。手机号码已经作为各大互联网站的注册账户。同样,身...

Pycharm最新激活码2019(推荐)

Pycharm最新激活码2019(推荐)

pycharm2019激活码是专门针对与pycharm2019这一款软件而研发的激活码,能够完美激活软件,并且能够支持2019.1版本,理论上也能够支持后继的2019.2,2019.3,...

示例详解Python3 or Python2 两者之间的差异

示例详解Python3 or Python2 两者之间的差异

每门编程语言在发布更新之后,主要版本之间都会发生很大的变化。 在本文中,Vinodh Kumar 通过示例解释了 Python 2 和 Python 3 之间的一些重大差异,以帮助说明语...

django启动uwsgi报错的解决方法

django启动uwsgi报错的解决方法

uwsgi介绍 uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。 要注意 W...

Python中暂存上传图片的方法

很简单的代码,记录一下。 复制代码 代码如下:     import Image     image = Image.open...