您好,登錄后才能下訂單哦!
python 通過手機號識別出對應的微信性別,具體代碼如下所述:
def getGender(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 if AccNotExist: self.d.watchers.reset() return "用戶不存在" elif AccException: self.d.watchers.reset() return "被搜帳號狀態異常,無法顯示" elif OperationFrequently: self.d.watchers.reset() if self.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 return gender else: self.d(resourceId="com.tencent.mm:id/kb").click() # back return "用戶未設置性別" def write_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") def writesheet(self,sheet): for i in range(0, index): for j in range(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) def write_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) # 獲取轉化后工作簿中的第一個表格 for i in range(0, index): for j in range(0, len(value[i])): new_worksheet.write(i + rows_old, j, value[i][j]) # 追加寫入數據,注意是從i+rows_old行開始寫入 new_workbook.save(pathfile) # 保存工作簿 # print("%s【追加】寫入數據成功!" % pathfile) def read_excel_xls(self,pathfile, sheet_name): workbook = xlrd.open_workbook(pathfile) # 打開工作簿 sheets = workbook.sheet_names() # 獲取工作簿中的所有表格 worksheet = workbook.sheet_by_name(sheet_name) # 獲取工作簿中所有表格中的的第一個表格 for i in range(0, worksheet.nrows): for j in range(0, worksheet.ncols): print(worksheet.cell_value(i, j), "\t", end="") # 逐行逐列讀取數據
ps:下面看下python 通過電話號碼獲取微信性別信息
getWeixinPro.py
# coding:utf-8 import sys,re,xlrd from xlwt import * reload(sys) sys.setdefaultencoding('utf8') from uiautomator import device as d import unittest import time #打開excel def openExcel(file): try: data = xlrd.open_workbook(file) return data except Exception as e: print (str(e)) def floatToInt(list): realList = [] for value in list: if (type(value) == float): value = str(value) value = re.sub('\.0*$', "", value) value = str(value).rstrip() realList.append(value) return realList class Mytest(unittest.TestCase): #初始化工作 def setUp(self): print ("--------------初始化工作") #退出清理工作 # def tearDown(self): # print ("--------------退出清理工作") #測試 def test_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('微信號-性別') for row in range(table.nrows): tel=floatToInt(table.row_values(row))[0] if not d(resourceId="com.tencent.mm:id/h3").exists: if d(resourceId='com.tencent.mm:id/h7').exists: d(resourceId='com.tencent.mm:id/h7').click() if d(resourceId="com.tencent.mm:id/h3").exists: d(resourceId="com.tencent.mm:id/h3").clear_text() d(resourceId="com.tencent.mm:id/h3").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) if isTriggered: d.watcher(tel).remove() if not isTriggered: if d(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, "用戶沒有設置性別") if d(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__': # from uiautomator import device as d # # # print(d.info) # # d.press.power() unittest.main()
總結
以上所述是小編給大家介紹的python 通過手機號識別出對應的微信性別,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。