手機號性別檢測 手機號實名檢測
我們通過程式進行
比如 appium自動化測試工具,adb命令,android自動化測試Uiautomator框架 等。。
adb命令通用,python呼叫adb很方便,所以那我們就用adb寫自動獲取程式碼。
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy rotation="0">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.tencent.mm" content-desc="當前所在頁面,詳細資料" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1920]">
<node index="0" text="" resource-id="com.tencent.mm:id/dgn" class="android.widget.FrameLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1920]">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1920]">
<node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1920]">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,60][1080,1920]">
<node index="0" text="" resource-id="com.tencent.mm:id/gz" class="android.view.ViewGroup" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,60][1080,1920]">
<node index="0" text="" resource-id="com.tencent.mm:id/h0" class="android.widget.FrameLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,60][1080,204]">
<node index="0" text="" resource-id="com.tencent.mm:id/h1" class="android.view.ViewGroup" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,60][1080,204]">
<node index="0" text="" resource-id="com.tencent.mm:id/gw" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,60][912,204]">
<node index="0" text="" resource-id="com.tencent.mm:id/i1" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,60][146,204]">
<node index="0" text="" resource-id="com.tencent.mm:id/i2" class="android.widget.ImageView" package="com.tencent.mm" content-desc="返回" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,60][144,204]" />
<node index="1" text="" resource-id="com.tencent.mm:id/hf" class="android.widget.ImageView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[144,96][146,168]" /></node>
<node index="1" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[182,60][398,204]">
<node index="0" text="詳細資料" resource-id="android:id/text1" class="android.widget.TextView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[182,95][398,168]" /></node>
</node>
<node index="1" text="" resource-id="" class="android.support.v7.widget.LinearLayoutCompat" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[912,60][1080,204]">
<node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[912,60][1080,204]">
<node index="0" text="" resource-id="" class="android.widget.RelativeLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[912,60][1080,204]">
<node index="0" text="" resource-id="com.tencent.mm:id/hi" class="android.widget.ImageButton" package="com.tencent.mm" content-desc="更多" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[912,60][1080,204]" /></node>
</node>
</node>
</node>
</node>
<node index="1" text="" resource-id="android:id/content" class="android.widget.FrameLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,204][1080,1920]">
<node index="0" text="" resource-id="com.tencent.mm:id/c8f" class="android.widget.FrameLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,204][1080,1920]">
<node index="0" text="" resource-id="com.tencent.mm:id/c_z" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,204][1080,1920]">
<node index="0" text="" resource-id="android:id/list" class="android.widget.ListView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="true" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[0,204][1080,1920]">
<node index="0" text="" resource-id="android:id/title" class="android.widget.TextView" package="com.tencent.mm" content-desc="分隔欄" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,204][1080,264]" />
<node index="1" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,264][1080,726]">
<node index="0" text="" resource-id="com.tencent.mm:id/anj" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,264][1080,528]">
<node index="0" text="" resource-id="com.tencent.mm:id/pz" class="android.widget.ImageView" package="com.tencent.mm" content-desc="頭像" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[42,300][234,492]" />
<node index="1" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[306,300][1044,383]">
<node index="0" text="" resource-id="com.tencent.mm:id/ank" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[306,306][1044,371]">
<node index="0" text="李鵬 " resource-id="com.tencent.mm:id/q0" class="android.widget.TextView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[306,306][414,371]" />
<node index="1" text="" resource-id="com.tencent.mm:id/anl" class="android.widget.ImageView" package="com.tencent.mm" content-desc="男" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[423,308][484,369]" /></node>
</node>
</node>
<node index="1" text="" resource-id="" class="android.widget.TextView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,528][1080,529]" />
<node index="2" text="" resource-id="com.tencent.mm:id/anz" class="android.view.View" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,529][1080,589]" />
<node index="3" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,589][1080,726]">
<node index="0" text="設定備註和標籤" resource-id="com.tencent.mm:id/ao0" class="android.widget.TextView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,589][1080,726]" /></node>
</node>
<node index="2" text="" resource-id="android:id/title" class="android.widget.TextView" package="com.tencent.mm" content-desc="分隔欄" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,726][1080,786]" />
<node index="3" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,786][1080,930]">
<node index="0" text="" resource-id="com.tencent.mm:id/ij" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[42,786][1038,930]">
<node index="0" text="" resource-id="com.tencent.mm:id/jg" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[42,801][496,914]">
<node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[42,825][288,890]">
<node index="0" text="地區" resource-id="android:id/title" class="android.widget.TextView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[42,825][288,890]" /></node>
<node index="1" text="" resource-id="com.tencent.mm:id/c_d" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[306,829][496,885]">
<node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[306,829][496,885]">
<node index="0" text="河南 信陽" resource-id="android:id/summary" class="android.widget.TextView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[306,829][496,885]" /></node>
</node>
</node>
</node>
</node>
<node index="4" text="" resource-id="android:id/title" class="android.widget.TextView" package="com.tencent.mm" content-desc="分隔欄" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,930][1080,990]" />
<node index="5" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,990][1080,1170]">
<node index="0" text="新增到通訊錄" resource-id="com.tencent.mm:id/an_" class="android.widget.Button" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[42,990][1038,1134]" /></node>
<node index="6" text="" resource-id="android:id/title" class="android.widget.TextView" package="com.tencent.mm" content-desc="分隔欄" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,1170][1080,1230]" />
<node index="7" text="" resource-id="" class="android.widget.LinearLayout" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,1230][1080,1310]">
<node index="0" text="" resource-id="android:id/title" class="android.widget.TextView" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,1230][1080,1310]" /></node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
<node index="1" text="" resource-id="android:id/statusBarBackground" class="android.view.View" package="com.tencent.mm" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,60]" /></node>
</hierarchy>
發現 性別在 content-desc=”男” 這個地方 ,
一共有三種狀態
content-desc=”男”
content-desc=”女”
xml原始碼沒有就是對方性別未知
找到包含 resource-id=”com.tencent.mm:id/anl” 為基準的節點,包含在
我們先找到包含resource-id=”com.tencent.mm:id/anl”的這一行,
1 首先獲取手機裝置
2 電腦端使用python程式通過adb命令控制手機
3 拿出手機端的頁面
4 進行匹配並列印
開始我們的編寫程式碼:
import os,re
# 獲取所有的手機裝置
def getDevicesAll():
devices = []
try:
for dName_ in os.popen("adb devices"):
if "\t" in dName_:
if dName_.find("emulator") < 0:
devices.append(dName_.split("\t")[0])
devices.sort(cmp=None, key=None, reverse=False)
except:
pass
print(u"\n裝置名稱: %s \n總數量:%s臺" % (devices, len(devices)))
return devices
# 匯出手機端當前頁面元素
def export(devices_name):
# 頁面xml儲存到手機儲存
step1 = os.popen('adb -s {0} shell uiautomator dump /sdcard/{1}.xml'.format(devices_name,devices_name)).read()
if step1.find('UI') != -1:
print(devices_name+'\txml寫進手機儲存成功')
# 頁面xml從手機儲存推送到電腦,和當前執行程式同級
os.popen('adb -s {0} pull /sdcard/{1}.xml '.format(devices_name,devices_name))
print(devices_name+"\txml推送到電腦成功")
with open(devices_name + ".xml",encoding="utf-8") as f:
res = f.read()
return res
else:
print(devices_name+"\txml寫進手機儲存失敗")
return "null"
# 匹配函式
def check_line(res,find_str):
list1 = re.findall( '<[^<]*?' + find_str + '[^>]*?>', res)
if list1:
return list1[0]
return "null"
def main():
# 以resource-id為基準進行匹配
findstr = 'resource-id="com.tencent.mm:id/anl"'
devices = getDevicesAll()
for d_name in devices:
res = export(d_name)
if res!="null":
result = check_line(res,findstr)
if result=="null":
print("此手機號性別未知")
elif result.find("男") != -1:
print("此手機號性別男")
elif result.find("女") != -1:
print("此手機號性別女")
if __name__=="__main__":
main()
————————————————
getDevicesAll函式獲取所有連線電腦的USB手機裝置,獲取裝置名稱
export函式獲取當前連線的手機的頁面
check_line函式拿到準確的一行,拿不到說明是未知性別
main函式進行邏輯判斷等。
有需求的可以聯絡我!
本作品採用《CC 協議》,轉載必須註明作者和本文連結