上面文章写了一些使用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);
}
///
/// 1 获取好友列表
///
/// 路径
/// Cookie
///
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": ""
}
]
}
下一篇会贴出来使用cefsharp 模拟人工创建淘宝客后台的推广位和批量商品信息下载。