小編給大家分享一下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看完了這篇文章,相信你對“Python怎么實現手機號自動判斷男女性別”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。