def collectTOP(): last = None # 点击列表组件左上角空白部分,激活右窗口 collect.Click(10, 10) while 1: item = collect.GetFirstChildControl().TextControl() print(item.Name) item.SendKeys("{PAGEUP 10}") if last == item.Name: break last = item.Name
def read_collect_info(ico_tag): # 根据按钮相对位置找到文本节点的位置 desc_tags = ico_tag.GetNextSiblingControl().GetNextSiblingControl().GetChildren() content = "\n".join([desc_tag.Name for desc_tag in desc_tags])
time_tag, source_tag = ico_tag \ .GetParentControl().GetParentControl() \ .GetNextSiblingControl().GetNextSiblingControl() \ .GetChildren()[:2] time, source = time_tag.Name, source_tag.Name return content, time, source
# 每个UI列表元素内部都必定存在左侧的图标按钮 ico_tag = collect.GetFirstChildControl().ButtonControl() content, time, source = read_collect_info(ico_tag) print(content, time, source, sep="\n")
可以看到数据都正确的提取:
测试2类缺数据的异常节点也没有问题:
对于每条收藏的链接我们需要右键点击复制链接后,再从剪切板读取:
def get_meau_item(name): menu = wechatWindow.MenuControl() menu_items = menu.GetLastChildControl().GetFirstChildControl().GetChildren() for menu_item in menu_items: if menu_item.ControlTypeName != "MenuItemControl": continue if menu_item.Name == name: return menu_item
def collectTOP(collect): last = None # 点击列表组件左上角空白部分,激活右窗口 collect.Click(10, 10) while 1: item = collect.GetFirstChildControl().TextControl() print(item.Name) item.SendKeys("{PAGEUP 10}") if last == item.Name: break last = item.Name
def read_collect_info(ico_tag): # 根据按钮相对位置找到文本节点的位置 desc_tags = ico_tag.GetNextSiblingControl().GetNextSiblingControl().GetChildren() content = "\n".join([desc_tag.Name for desc_tag in desc_tags])
time_tag, source_tag = ico_tag \ .GetParentControl().GetParentControl() \ .GetNextSiblingControl().GetNextSiblingControl() \ .GetChildren()[:2] time, source = time_tag.Name, source_tag.Name return content, time, source
def get_meau_item(name): menu = wechatWindow.MenuControl() menu_items = menu.GetLastChildControl().GetFirstChildControl().GetChildren() for menu_item in menu_items: if menu_item.ControlTypeName != "MenuItemControl": continue if menu_item.Name == name: return menu_item
result = [] last = None while 1: page = [] text = collect.GetFirstChildControl().TextControl().Name if text == last: # 首元素无变化说明已经到底部 break last = text items = collect.GetChildren() for i, item in enumerate(items): # 每个UI列表元素内部都必定存在左侧的图标按钮 ico_tag = item.ButtonControl() content, time, source = read_collect_info(ico_tag) # 对首尾位置的节点作偏移处理 item.RightClick(y=-5 if i == 0 else 5 if i == len(items)-1 else None) get_meau_item("复制地址").Click() url = auto.GetClipboardText() row = [content, time, source, url] print("\r", row, end=" "*1000) page.append(row) result.extend(page) item.SendKeys("{PAGEDOWN}")
def get_meau_item(name): menu = wechatWindow.MenuControl() menu_items = menu.GetLastChildControl().GetFirstChildControl().GetChildren() for menu_item in menu_items: if menu_item.ControlTypeName != "MenuItemControl": continue if menu_item.Name == name: return menu_item