python 通过手机号识别出对应的微信性别(实例代码)
python通过手机号识别出对应的微信性别,具体代码如下所述:
defgetGender(self,tel): self.d(resourceId="com.tencent.mm:id/kh").clear_text() self.d(resourceId="com.tencent.mm:id/kh").set_text(tel) self.d(resourceId="com.tencent.mm:id/mf").click() time.sleep(1) self.d.watcher("AccNotExist").when(text="该用户不存在").click(resourceId="com.tencent.mm:id/kd") self.d.watcher("AccException").when(text="被搜帐号状态异常,无法显示").click(resourceId="com.tencent.mm:id/kd" self.d.watchers.run() AccNotExist=self.d.watcher("AccNotExist").triggered AccException=self.d.watcher("AccException").triggered OperationFrequently=self.d.watcher("OperationFrequently").triggered ifAccNotExist: self.d.watchers.reset() return"用户不存在" elifAccException: self.d.watchers.reset() return"被搜帐号状态异常,无法显示" elifOperationFrequently: self.d.watchers.reset() ifself.d(resourceId="com.tencent.mm:id/b3y").exists: gender=self.d(resourceId="com.tencent.mm:id/b3y").info['contentDescription'] self.d(resourceId="com.tencent.mm:id/kb").click()#back returngender else: self.d(resourceId="com.tencent.mm:id/kb").click()#back return"用户未设置性别" defwrite_excel_xls(self,pathfile,value): index=len(value) workbook=xlwt.Workbook()#新建一个工作簿 sheet1=workbook.add_sheet("boy")#在工作簿中新建一个表格 sheet2=workbook.add_sheet("girl") sheet3=workbook.add_sheet("NotSet") sheet4=workbook.add_sheet("NotExist") sheet5=workbook.add_sheet("AccountE") defwritesheet(self,sheet): foriinrange(0,index): forjinrange(0,len(value[i])): sheet.write(i,j,value[i][j])#像表格中写入数据(对应的行和列) workbook.save(pathfile)#保存工作簿 writesheet(self,sheet1) writesheet(self,sheet2) writesheet(self,sheet3) writesheet(self,sheet4) writesheet(self,sheet5) defwrite_excel_xls_append(self,pathfile,sheet_name,value): index=len(value)#获取需要写入数据的行数 workbook=xlrd.open_workbook(pathfile)#打开工作簿 #sheets=workbook.sheet_names()#获取工作簿中的所有表格 worksheet=workbook.sheet_by_name(sheet_name)#获取工作簿中所有表格中的的第一个表格 rows_old=worksheet.nrows#获取表格中已存在的数据的行数 new_workbook=copy(workbook)#将xlrd对象拷贝转化为xlwt对象 new_worksheet=new_workbook.get_sheet(sheet_name)#获取转化后工作簿中的第一个表格 foriinrange(0,index): forjinrange(0,len(value[i])): new_worksheet.write(i+rows_old,j,value[i][j])#追加写入数据,注意是从i+rows_old行开始写入 new_workbook.save(pathfile)#保存工作簿 #print("%s【追加】写入数据成功!"%pathfile) defread_excel_xls(self,pathfile,sheet_name): workbook=xlrd.open_workbook(pathfile)#打开工作簿 sheets=workbook.sheet_names()#获取工作簿中的所有表格 worksheet=workbook.sheet_by_name(sheet_name)#获取工作簿中所有表格中的的第一个表格 foriinrange(0,worksheet.nrows): forjinrange(0,worksheet.ncols): print(worksheet.cell_value(i,j),"\t",end="")#逐行逐列读取数据
ps:下面看下python通过电话号码获取微信性别信息
getWeixinPro.py
#coding:utf-8 importsys,re,xlrd fromxlwtimport* reload(sys) sys.setdefaultencoding('utf8') fromuiautomatorimportdeviceasd importunittest importtime #打开excel defopenExcel(file): try: data=xlrd.open_workbook(file) returndata exceptExceptionase: print(str(e)) deffloatToInt(list): realList=[] forvalueinlist: if(type(value)==float): value=str(value) value=re.sub('\.0*$',"",value) value=str(value).rstrip() realList.append(value) returnrealList classMytest(unittest.TestCase): #初始化工作 defsetUp(self): print("--------------初始化工作") #退出清理工作 #deftearDown(self): #print("--------------退出清理工作") #测试 deftest_33(self): #d.screen.on() file='1.xlsx' print("check[+]%s"%file) data=openExcel(file) sheets=data.sheets() table=sheets[0] writeFile=Workbook(encoding='utf-8') #指定file以utf-8的格式打开 writeTable=writeFile.add_sheet('微信号-性别') forrowinrange(table.nrows): tel=floatToInt(table.row_values(row))[0] ifnotd(resourceId="com.tencent.mm:id/h2").exists: ifd(resourceId='com.tencent.mm:id/h7').exists: d(resourceId='com.tencent.mm:id/h7').click() ifd(resourceId="com.tencent.mm:id/h2").exists: d(resourceId="com.tencent.mm:id/h2").clear_text() d(resourceId="com.tencent.mm:id/h2").set_text(tel) d(resourceId='com.tencent.mm:id/b20').click() d.watcher(tel).when(resourceId="com.tencent.mm:id/aes").when(text="确定")\ .click(text="确定") d.watchers.run() isTriggered=d.watcher(tel).triggered print(isTriggered) ifisTriggered: d.watcher(tel).remove() ifnotisTriggered: ifd(resourceId='com.tencent.mm:id/agf').exists: contentDescription=d(resourceId='com.tencent.mm:id/agf').info['contentDescription'] print("tel=%s,sex=%s"%(tel,contentDescription)) writeTable.write(row,0,tel) writeTable.write(row,1,contentDescription) else: print("tel=%s,sex=%s"%(tel,"用户没有设置性别")) writeTable.write(row,0,tel) writeTable.write(row,1,"用户没有设置性别") ifd(resourceId='com.tencent.mm:id/h7').exists: d(resourceId='com.tencent.mm:id/h7').click() else: print("tel=%s,sex=%s"%(tel,"没有该用户")) writeTable.write(row,0,tel) writeTable.write(row,1,"没有该用户") time.sleep(3) writeFile.save('wx_tel_sex.xlsx') print("--------------测试1") if__name__=='__main__': #fromuiautomatorimportdeviceasd # # #print(d.info) # #d.press.power() unittest.main()
总结
以上所述是小编给大家介绍的python通过手机号识别出对应的微信性别,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。