学习文章—(Python实践)Python实现手机号自动判断男女性别

作者:西西里传说
来源:CSDN博客


链接:
https://blog.csdn.net/qq_15687823/article/details/103645268
如果你觉得有用欢迎关注我吧
本文性别判断主要依靠airtest中的自动化测试实现
通过自动对比支付宝页面男女图像,从而实现男女判断

代码如下:
男女判断函数:

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

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

<code>// An highlighted block

def

scoll

()

:

try

: swipe(v1=(

629

,

1750

),v2=(

629

,

310

))

except

: print(

"can't go back to the main page"

)/<code>

刷选函数:

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

"出错,跳过!"

)/<code>

综合:

<code>// An highlighted block
 
__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

/<code>

效果如下(只筛选了女):

学习文章—(Python实践)Python实现手机号自动判断男女性别

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

结尾:

最后多说一句,小编是一名python开发工程师,这里有我自己整理了一套最新的python系统学习教程,包括从基础的python脚本到web开发、爬虫、数据分析、数据可视化、机器学习等。想要这些资料的可以关注小编,并在后台私信小编:“01”即可领取


分享到:


相關文章: