Exemplo n.º 1
0
        public static string GetMid(string uid, string weiboid)
        {
            string mid  = "";
            string html = XHttp.GetHttpResult($"https://weibo.com/{uid}/{weiboid}");

            //取出所有script块
            Regex           reg     = new Regex(@"<script>(?<data>.*)</script>", RegexOptions.IgnoreCase);
            MatchCollection matches = reg.Matches(html);

            foreach (Match match in matches)
            {
                try
                {
                    string data = (match.Groups["data"].Value);
                    data = data.Replace("FM.view(", "");

                    data = data.Substring(0, data.Length - 1);
                    WeiboInfoJsonModel w = JsonConvert.DeserializeObject <WeiboInfoJsonModel>(data);
                    if (w.ns == "pl.content.weiboDetail.index" && w.domid == "Pl_Official_WeiboDetail__73")
                    {
                        w.html = w.html.Replace("\t", "").Replace("\r", "").Replace("\n", "");
                        Regex regmid = new Regex(@"mid=\""(?<mid>.+?)\""", RegexOptions.IgnoreCase);
                        mid = regmid.Match(w.html).Groups["mid"].Value;
                        break;
                    }
                }
                catch
                {
                }
            }

            return(mid);
        }
Exemplo n.º 2
0
        static UserInfoModel GetUserInfo(string url)
        {
            Console.WriteLine("开始获取:" + url);

            var result = new UserInfoModel();

            result.Url = url;
            string userinfohtml = XHttp.GetHttpResult(url);

            //取出昵称
            Regex regnickname = new Regex(@"\$CONFIG\['onick'\]='(?<nickname>.*)';", RegexOptions.IgnoreCase);

            result.NickName = regnickname.Match(userinfohtml).Groups["nickname"].Value;


            //正则取出所有script块
            Regex reg = new Regex(@"<script>(?<data>.*)</script>", RegexOptions.IgnoreCase);

            // 搜索匹配的字符串
            MatchCollection matches = reg.Matches(userinfohtml);


            // 取得匹配项列表
            foreach (Match match in matches)
            {
                try
                {
                    string data = (match.Groups["data"].Value);
                    data = data.Replace("FM.view(", "");

                    data = data.Substring(0, data.Length - 1);
                    WeiboInfoJsonModel w = JsonConvert.DeserializeObject <WeiboInfoJsonModel>(data);
                    if (w.ns == "pl.header.head.index" && w.domid == "Pl_Official_Headerv6__1")
                    {
                        //取出性别
                        w.html = w.html.Replace("\t", "").Replace("\r", "").Replace("\n", "");


                        Regex  regsex   = new Regex(@"<a><i class=\""(?<sex>.+?)\""></i></a>", RegexOptions.IgnoreCase);
                        string sexstyle = regsex.Match(w.html).Groups["sex"].Value;
                        result.Sex = sexstyle.IndexOf("female") != -1 ? "女" : "男";
                    }
                    if (w.ns == "pl.content.homeFeed.index" && w.domid == "Pl_Core_UserInfo__6")
                    {
                        //正则取出所有资料
                        Regex reg2 = new Regex(@"<li class=\""item S_line2 clearfix\"">(?<data>.+?)</li>", RegexOptions.IgnoreCase);
                        w.html = w.html.Replace("\t", "").Replace("\r", "").Replace("\n", "");

                        // 搜索匹配的字符串
                        MatchCollection matches2 = reg2.Matches(w.html);


                        // 取得匹配项列表
                        foreach (Match match2 in matches2)
                        {
                            string data2 = (match2.Groups["data"].Value);

                            Regex  regcontent = new Regex(@"<span class=""item_text W_fl"">(?<content>.+?)</span>", RegexOptions.IgnoreCase);
                            string content    = regcontent.Match(data2).Groups["content"].Value;
                            content = content.Replace(" ", "");
                            if (data2.IndexOf("ficon_starmark") != -1)
                            {
                                //等级
                            }
                            else if (data2.IndexOf("ficon_cd_place") != -1)
                            {
                                //地区
                                result.Location = content;
                            }
                            else if (data2.IndexOf("ficon_constellation") != -1)
                            {
                                //生日
                                result.Birthday = content;
                            }
                            else if (data2.IndexOf("ficon_pinfo") != -1)
                            {
                                //简介
                                result.Note = content;
                            }
                        }

                        break;
                    }
                }
                catch
                {
                }
            }
            Console.WriteLine($"--> 昵称:{result.NickName},性别:{result.Sex},生日:{result.Birthday},地区:{result.Location},主页:{result.Url}");
            return(result);
        }