使用 uiautomation 获取通讯录好友信息

在这里插入图片描述

# coding:utf-8
import uiautomation as auto
import time
import pandas as pd
wechatWindow = auto.WindowControl(searchDepth=1,Name='微信',className='WeChatMainWndForPC')
button = wechatWindow.ButtonControl(Name='通讯录')
button.Click()
wechatWindow.SetActive()
contents = wechatWindow.ListControl(Name="联系人")
# button = wechatWindow.ButtonControl(Name='***'
result = []
def deli():

    threeLays = wechatWindow.GetLastChildControl().GetLastChildControl().GetLastChildControl()
    tag = wechatWindow.EditControl(searchDepth=10, foundIndex=2)
    tmp = tag.GetParentControl().GetParentControl()
    nikeName = tag.Name
    items = tmp.GetParentControl().GetNextSiblingControl().GetNextSiblingControl().GetChildren()
    a1 = []
    row = {'微信号': '', '地址': ''}
    for item in items:
        try:

            line = item.GetChildren()
            # print(line[0].Name)
            de = line[1].Name.split(" ")
            # print(de)
            a1.append(line[1].Name)
            # print(")))))))))")
        except Exception as e:
            print(e)
        # print(de)
    # print(a1)
    row['微信号'] = a1[2]
    row['地址'] = a1[1]
    row['备注'] = a1[0]
    result.append(row)


# button.Click()

# print(wechatWindow.GetLastChildControl().GetLastChildControl().GetChildren()[1:2])
# print(contents.GetChildren()[8].Name)

# a = wechatWindow.ButtonControl(Name='ContactListItem')
# a.Click()
# a.SendKeys('{PAGEDOWN}')
i = 8
j = 0
while 1:
    if j == 0:
        for list1 in range(8,len(contents.GetChildren())):
            contents.GetChildren()[list1].Click()
            # print(contents.GetChildren()[list1].Name)
            deli()
    else:
        for list1 in range(1,len(contents.GetChildren())):
            contents.GetChildren()[list1].Click()
            # print(contents.GetChildren()[list1].Name)
            deli()

    print(len(contents.GetChildren()))
    if len(contents.GetChildren())>10:
        contents.GetChildren()[4].Click()
        time.sleep(1)
        contents.GetChildren()[4].SendKeys('{PAGEDOWN}')
    else:
        contents.GetChildren()[0].Click()
        time.sleep(1)
        contents.GetChildren()[0].SendKeys('{PAGEDOWN}')

    i = i+1
    j = j+1
    if i >9:
        break
"""
while 1 :
    c = contents.GetChildren()[i]
    c.Click()
    c.SendKeys('{PAGEDOWN}')
    print(c.Name)
    i=i+1
    if i> 20:
        break
"""
print(result)
dataTable = pd.DataFrame(result)
# print(dataTable)
dataTable.drop_duplicates(subset=['微信号'],keep='first',inplace=True)
# print(dataTable)
dataTable.to_excel("123.xlsx",sheet_name='微信通讯录好友备份',encoding='gb2312',columns=['微信号','地址','备注'])
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值