温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python怎么实现手机号自动判断男女性别

发布时间:2021-02-08 11:42:46 来源:亿速云 阅读:351 作者:小新 栏目:开发技术

小编给大家分享一下Python怎么实现手机号自动判断男女性别,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

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

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

Python怎么实现手机号自动判断男女性别Python怎么实现手机号自动判断男女性别

代码如下:

男女判断函数:

// 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

看完了这篇文章,相信你对“Python怎么实现手机号自动判断男女性别”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI