Ejemplo n.º 1
0
        /// <summary>
        /// 解析主页的访问用户
        /// </summary>
        /// <returns></returns>
        public void VisitParser()
        {
            this.Login();
            Result result   = this.Request(this.HomePageUrl);
            string pageHtml = result.Msg;

            if (string.IsNullOrWhiteSpace(pageHtml))
            {
                return;
            }
            NSoup.Nodes.Document  doc              = NSoup.NSoupClient.Parse(pageHtml);
            NSoup.Nodes.Element   wrapElement      = doc.GetElementById("show_style_01");
            NSoup.Select.Elements userElementNodes = wrapElement.GetElementsByTag("li");
            if (userElementNodes != null && userElementNodes.Count > 0)
            {
                //倒序排列,最新的在最后面
                IEnumerable <NSoup.Nodes.Element> userElements = userElementNodes.Reverse();
                foreach (NSoup.Nodes.Element userElement in userElements)
                {
                    NSoup.Nodes.Element picElement      = GetElementFirst(userElement.GetElementsByClass("pic"));
                    NSoup.Nodes.Element nameElement     = GetElementFirst(userElement.GetElementsByClass("user_name"));
                    NSoup.Nodes.Element userInfoElement = GetElementFirst(userElement.GetElementsByClass("user_info"));
                    NSoup.Nodes.Element dateElement     = GetElementFirst(userElement.GetElementsByClass("date"));
                    string   userName = nameElement == null ? "" : nameElement.Child(0).Text();
                    string   homePage = UriHelper.RemoveParams(nameElement == null ? "" : nameElement.Child(0).Attr("href"));
                    string   pic      = picElement.Child(0).Child(0).Attr("src");
                    DateTime date     = Convert.ToDateTime(dateElement.Text().Replace("到访:", ""));
                    string[] userInfo = StringHelper.SplitWhiteSpace(userInfoElement.Child(0).Text());
                    int      age      = Convert.ToInt32(userInfo[0].Replace("岁", ""));
                    string   addr     = userInfo.Length > 1 ? userInfo[1] : string.Empty;
                    string   userCode = homePage.Substring(homePage.LastIndexOf('/') + 1);

                    if (addr.Contains("广州") && !string.IsNullOrWhiteSpace(userCode))
                    {
                        FateUserInfo user = FateUserInfoManager.GetUser(userCode);
                        if (user == null)
                        {
                            user = new FateUserInfo()
                            {
                                CreateTime = DateTime.Now
                            };
                        }
                        user.ModifyTime   = DateTime.Now;
                        user.UserCode     = userCode;
                        user.Address      = addr;
                        user.Age          = age;
                        user.HeadFileName = pic;
                        user.UserName     = userName;

                        FateUserInfoManager.SaveOrUpdateUser(user);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void btnSync_Click(object sender, EventArgs e)
 {
     this.btnSync.Enabled = false;
     if (MsgBox.Confirm("确定要同步图片到本地文件夹?"))
     {
         try
         {
             string path = Dialog.GetFolder();
             if (!string.IsNullOrEmpty(path))
             {
                 IList <FateUserInfo> users = FateUserInfoManager.GetUserList();
                 if (users != null && users.Count > 0)
                 {
                     int total = users.Count;
                     this.progressSync.Maximum = total;
                     this.progressSync.Value   = 0;
                     for (int i = 0; i < users.Count; i++)
                     {
                         FateUserInfo user         = users[i];
                         string       fileUrl      = user.HeadFileName;
                         string       ext          = Path.GetExtension(fileUrl);
                         string       newFileName  = user.UserCode + ext;
                         string       saveFileName = Path.Combine(path, newFileName);
                         if (!File.Exists(saveFileName))
                         {
                             HttpDownload download = new HttpDownload(fileUrl, saveFileName);
                             download.Download();
                             this.progressSync.Value++;
                             Application.DoEvents();
                         }
                     }
                     MsgBox.Alert("同步完成");
                 }
             }
         }
         catch (Exception ex)
         {
             MsgBox.Alert("同步失败,错误信息:" + ex.Message);
         }
     }
     this.btnSync.Enabled = true;
 }
Ejemplo n.º 3
0
        private void ParseSearchResult(string searchResult)
        {
            string jsontext = StringHelper.DeleteEnd(searchResult.Replace("##jiayser##", ""), "//");

            if (string.IsNullOrWhiteSpace(jsontext))
            {
                return;
            }
            JObject jsonObj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsontext);

            bool isLogin     = ConvertHelper.ToBool(jsonObj["isLogin"].ToString());
            int  totalRecord = ConvertHelper.ToInt32(jsonObj["count"].ToString());
            int  pageCount   = ConvertHelper.ToInt32(jsonObj["pageTotal"].ToString());

            this.TotalRecord = totalRecord;
            this.PageCount   = pageCount;
            JArray userInfoArray = (JArray)jsonObj["userInfo"];

            foreach (JObject userInfo in userInfoArray)
            {
                string realUid        = ConvertHelper.ToString(userInfo["realUid"].ToString());
                string nickname       = ConvertHelper.ToString(userInfo["nickname"].ToString());
                string sex            = ConvertHelper.ToString(userInfo["sex"].ToString());
                string marriage       = ConvertHelper.ToString(userInfo["marriage"].ToString());
                int    height         = ConvertHelper.ToInt32(userInfo["height"].ToString());
                string education      = ConvertHelper.ToString(userInfo["education"].ToString());
                string work_location  = ConvertHelper.ToString(userInfo["work_location"].ToString());
                int    age            = ConvertHelper.ToInt32(userInfo["age"].ToString());
                string image          = ConvertHelper.ToString(userInfo["image"].ToString());
                string randTag        = ConvertHelper.ToString(userInfo["randTag"].ToString());
                string randListTag    = ConvertHelper.ToString(userInfo["randListTag"].ToString());
                string shortnote      = ConvertHelper.ToString(userInfo["shortnote"].ToString());
                string matchCondition = ConvertHelper.ToString(userInfo["matchCondition"].ToString());
                string rand           = randTag + randListTag;
                //匹配信息,去除html标签
                string          patch    = "(?:<[^>]+>)(.+?)(?:</[^>]+>)";
                MatchCollection maths    = Regex.Matches(rand, patch);
                List <string>   mathList = new List <string>();
                if (maths != null)
                {
                    foreach (Match item in maths)
                    {
                        string tagValue = item.Groups[1].Value;
                        if (!mathList.Contains(tagValue))
                        {
                            mathList.Add(tagValue);
                        }
                    }
                }
                rand = string.Join(",", mathList);
                FateUserInfo user = FateUserInfoManager.GetUser(realUid);
                if (user == null)
                {
                    user = new FateUserInfo()
                    {
                        CreateTime = DateTime.Now
                    };
                }
                user.ModifyTime   = DateTime.Now;
                user.UserCode     = realUid;
                user.Address      = work_location;
                user.Age          = age;
                user.HeadFileName = image;
                user.UserName     = nickname;
                user.Education    = education;
                user.Comment      = rand;
                user.Height       = height;
                user.ShortNote    = shortnote;
                user.Marriage     = marriage;
                //保存或更新用户
                FateUserInfoManager.SaveOrUpdateUser(user);
            }
        }