当前位置:   article > 正文

使用C#抓取微信消息_c#获取微信聊天内容

c#获取微信聊天内容

1. 找到打开的微信

AutomationElement wecath = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "WeChatMainWndForPC"));

2.  找到节点的方法

AutomationElement FindNode(AutomationElement element,string name)
        {  
            var list = element.FindAll(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
            if (list == null) return null; 

            foreach (System.Windows.Automation.AutomationElement item in list)
            {
                if (item.Current.Name == name)
                { 
                    return item; 
                }
                else if (item.Current.Name == name)
                {
                    return item; 
                }
                else
                {
                   var result = FindNode(item, name);
                   if (result != null) return result; 
                }
            } 
            return null;
        }

3. 找到左边最近聊天的节点

 var result= FindNode(wecath, "会话");  // 会话  消息
 MessageNode(message);

4. 找到打开的对话窗口节点

var message = FindNode(wecath, "消息");  

5. 打印消息

 void PrintMessage(AutomationElement element,string name="")
        { 
            var list = element.FindAll(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
            if (list == null) return;
             
            foreach (System.Windows.Automation.AutomationElement item in list)
            {
                Console.WriteLine(name + "Name:" + item.Current.Name + "  ClassName=" + item.Current.ClassName + "  类型:" + item.Current.LocalizedControlType + $"{item.Current.BoundingRectangle.Location}   {item.Current.AutomationId}");
                // PrintMessage(item, name + "   "); 
            }
        }

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/821756
推荐阅读
相关标签
  

闽ICP备14008679号