使用CEfSharp之旅实战(一): 抓取web微信自己的好友信息

上面文章写了一些使用cefsharp的内容和技巧 ,这篇文章主要写下实际 应用:

这里例子用的webwechat wx2.qq.com 做实例的。

通过登录web微信获取到获取通讯录的url:   https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?

            //开启线程,抓取用户列表并保存到数据库
            if (obj.Contains("https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?"))
            {
                modcssAsync();
                ///新加获取Cookie 
                WxorWx2 = 2;
                var cookieManager = CefSharp.Cef.GetGlobalCookieManager();
                CookieVisitor visitor = new CookieVisitor();
                visitor.SendCookie += Visitor_GetUin;
                cookieManager.VisitAllCookies(visitor);


                Thread getFriendsThread = new Thread(new ParameterizedThreadStart(getfriends));
                getFriendsThread.IsBackground = true;
                getFriendsThread.Name = DateTime.Now.ToString();
                getFriendsThread.Start((Object)obj);
            }  
 /// <summary>
        /// 1 获取好友列表    
        /// </summary>
        /// <param name="url">路径</param>
        /// <param name="myCookieContainer">Cookie</param>
        /// <returns></returns>
        public static JObject GetContactByUrl(string url, CookieContainer myCookieContainer1,string CookieStr)
        {
            try
            {
          
                StringBuilder content = new StringBuilder();
                HttpWebRequest request = HttpWebRequest.Create(url.ToString()) as HttpWebRequest;
                request.Method = "GET";
                request.CookieContainer = myCookieContainer1;
                CookiesContainer = myCookieContainer1;
                HttpWebResponse response = null;
                using (WebResponse wr = request.GetResponse())
                {
                    response = wr as HttpWebResponse;
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        StreamReader sReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                        // 开始读取数据
                        Char[] sReaderBuffer = new Char[256];
                        int count = sReader.Read(sReaderBuffer, 0, 256);
                        while (count > 0)
                        {
                            String tempStr = new String(sReaderBuffer, 0, count);
                            content.Append(tempStr);
                            count = sReader.Read(sReaderBuffer, 0, 256);
                        }
                        // 读取结束
                        sReader.Close();
                    }
                }

                JObject job = (JObject)JsonConvert.DeserializeObject(content.ToString());

                //Console.WriteLine("================获取通讯录是的CookieList================================");
                //Console.WriteLine(GetAllCookies(myCookieContainer1));
                //Console.WriteLine("================================================");
                return job;
            }
            catch (Exception ex)
            {
}
}

   获取到通讯录信息为一个json 字符串可自行解析。

   信息如下:

{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
}
,
"Count": 3,
"ContactList": [{
"Uin": 0,
"UserName": "@@01aea33427c286a7b577444df4eac4b41178eaeb3db784eb1ed434b2bfc80cff",
"NickName": "北京天津设计师群",
"HeadImgUrl": "/cgi-bin/mmwebwx-bin/webwxgetheadimg?seq=615460722&username=@@01aea33427c286a7b577444df4eac4b41178eaeb3db784eb1ed434b2bfc80cff&skey=",
"ContactFlag": 1,
"MemberCount": 129,
"MemberList": [{
"Uin": 0,
"UserName": "@2ed30e16babab19ab60198619e82bd02",
"NickName": "雪儿|ä¹èŠ³èˆžä¼ åª’",
"AttrStatus": 2151794919,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": "lix"
}
,{
"Uin": 0,
"UserName": "@d01b4a2bbcbc1e44fe0be53e1c71d14bdfdf64ec0289e9f0becd7862eea4a81c",
"NickName": "五哥",
"AttrStatus": 235965,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": ""
}
,{
"Uin": 0,
"UserName": "@df308c250ab3dbdf21d8b46ed97386b9eef70eaa2240b7ba05d77d4566319b14",
"NickName": "ä¾è²",
"AttrStatus": 233509,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": ""
}
,{
"Uin": 0,
"UserName": "@1d324615827361ab3e17ebb276c8e2476fe924a12caae99c528daee449bff527",
"NickName": "å©·~å©·",
"AttrStatus": 2164265061,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": ""
}
,{
"Uin": 0,
"UserName": "@b1bf531545704729d422b953fdebd72e5e86441fda3f838e3d7d297eaa0d2e84",
"NickName": "瑶瑶",
"AttrStatus": 4133,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": ""
}
,{
"Uin": 0,
"UserName": "@4a78a5ebd02c646f61919545a1c5f221e011346eba4562e4fcc1a06a112d1169",
"NickName": "AA68元3天瘦10斤,想瘦加我",
"AttrStatus": 104709,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "AA68元3天瘦10斤,想瘦加我6-3",
"KeyWord": ""
}
,{
"Uin": 0,
"UserName": "@f9507da241ec87a6428b7a369a83d2e86767b86c13867adb544d81d686a711ba",
"NickName": "筱爱",
"AttrStatus": 102437,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": ""
}
],
"RemarkName": "",
"HideInputBarFlag": 0,
"Sex": 0,
"Signature": "",
"VerifyFlag": 0,
"OwnerUin": 0,
"PYInitial": "P8H9W10S",
"PYQuanPin": "pao8he9wan10shang",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"StarFriend": 0,
"AppAccountFlag": 0,
"Statues": 0,
"AttrStatus": 0,
"Province": "",
"City": "",
"Alias": "",
"SnsFlag": 0,
"UniFriend": 0,
"DisplayName": "",
"ChatRoomId": 0,
"KeyWord": "",
"EncryChatRoomId": "@17f654c7905cdfafa0fa31513ab991bd",
"IsOwner": 0
}
]
}

 下一篇会贴出来使用cefsharp 模拟人工创建淘宝客后台的推广位和批量商品信息下载。


猜你喜欢

转载自blog.csdn.net/u010919083/article/details/80566649
今日推荐