C#采集:图灵机器人信息

Dictionary<string, string> users = new Dictionary<string, string>();
users.Add("userName1", "password");
users.Add("userName2", "password");
users.Add("userName3", "password");
DataTable dt = new DataTable() ;
dt.Columns.Add("UserName");
dt.Columns.Add("apiKey");
dt.Columns.Add("robtName");
dt.Columns.Add("chatCount");
foreach (var item2 in users)
{
    var httpHelper = new HttpHelper();
    var login = httpHelper.GetHtml(new HttpItem() { URL = string.Format("http://sso.tuling123.com/sso-api/login/p/1?username={0}&password={1}", item2.Key, item2.Value) });
    var homePage = httpHelper.GetHtml(new HttpItem() { URL = "http://www.tuling123.com/member/robot/index.jhtml", Cookie = login.Cookie });
    Dictionary<string, int> result = new Dictionary<string, int>();
    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(homePage.Html);
    var robots = doc.DocumentNode.SelectNodes("//ul[@class='robots']/li");
    for (int i = 0; i < robots.Count - 1; i++)
    {
        var item = robots[i];
        var dr = dt.NewRow();
        dr["UserName"] = item2.Key;
        dr["apiKey"] = item.Attributes["apikey"].Value;
        dr["robtName"] = item.SelectSingleNode("div[@class='robot-name']").InnerText;
        dr["chatCount"] = item.SelectSingleNode("div[@class='before-chat']").InnerText.Replace("今日聊天数量:", "").Trim();
        dt.Rows.Add(dr);
    }
    dt.Rows.Add(dt.NewRow());
}

 

posted @ 2018-05-04 20:39  随便取个名字算了  阅读(762)  评论(0编辑  收藏  举报