Beispiel #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);
        }
Beispiel #2
0
        public static LikeModel GetPageLikeLinks(string mid, int page = 1)
        {
            string likehtml = XHttp.GetHttpResult($"https://weibo.com/aj/v6/like/big?ajwvr=6&mid={mid}&page={page}&__rnd=1531705846965");

            likehtml = likehtml.Replace("\\", "");
            var result = new LikeModel();

            //提取总页数
            Regex regtotalpage     = new Regex("\"totalpage\":(?<totalpage>.*),\"pagenum\"");
            var   regtotalpagemath = regtotalpage.Match(likehtml);

            int.TryParse(regtotalpagemath.Groups["totalpage"].Value, out int totalpage);
            result.TotalPage = totalpage;
            Regex           reg     = new Regex(@"<a\b[^<>]*?\bhref[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<url>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
            MatchCollection matches = reg.Matches(likehtml);

            foreach (Match match in matches)
            {
                string data = (match.Groups["url"].Value);
                if (!string.IsNullOrEmpty(data) && result.UserLinks.IndexOf(data) == -1 && data.IndexOf("http") != -1)
                {
                    result.UserLinks.Add(data);
                }
            }
            return(result);
        }
Beispiel #3
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);
        }