Exemple #1
0
        //public Title(string url)
        //{


        //    this.Url = url;

        //    GetHtml();

        //}

        private void GetHtml()
        {
            //try
            //{



            string html = HttpHelper.HttpGet(this.Url, Encoding.UTF8, null, false, true);

            if (html.Contains("PageData.forum"))
            {
                maxPn = int.Parse(HttpHelper.Jq(html, "共<span class=\"red\">", "<"));

                html = html.Replace("j_d_post_content \" style=\"display:none;\">            ", "j_d_post_content \" style=\"display:;\">            ");


                Content.AddRange(HttpHelper.P_jq(html, "d_post_content j_d_post_content \" style=\"display:;\">            ", "</div><br>"));


                if (Content.Count == 0)
                {
                    Content.AddRange(HttpHelper.P_jq(html, "d_post_content j_d_post_content  clearfix\">            ", "</div><br>"));
                }

                Authors.AddRange(HttpHelper.P_jq(html, "<img username=\"", "\""));


                Pids.AddRange(HttpHelper.P_jq(html, "id=\"post_content_", "\""));

                //Times.AddRange(HttpHelper.P_jq(html, "楼</span><span class=\"tail-info\">", "<"));
                //if (Times.Count == 0) Times.AddRange(HttpHelper.P_jq(html, "&quot;date&quot;:&quot;", "&quot;"));

                Level.AddRange(HttpHelper.P_jq(html, "d_badge_lv\">", "<"));


                Uids.AddRange(HttpHelper.P_jq(html, "class=\"d_name\" data-field='{&quot;user_id&quot;:", "}'"));
                //<img username="******" class="" src="http://tb.himg.baidu.com/sys/portrait/item/be28e587a1e5bf83e5a682e99baa750c"/>
                //<img username.*?(http://tb.himg.baidu.com/sys/portrait/item/[0-9][a-z][^"]+?)"/>
                //<img username="******" class="" src="//tb2.bdstatic.com/tb/static-pb/img/head_80.jpg" data-tb-lazyload="http://tb.himg.baidu.com/sys/portrait/item/d651e7bc93e5928ce6849fe8a789dc20"/>
                //Himgs.AddRange(HttpHelper.P_jq(html, "http://tb.himg.baidu.com/sys/portrait/item/3c5d14f80a4f78f09261e7fe48043a79", "\""));
                //http://h.hiphotos.baidu.com/forum/sign=3c5d14f80a4f78f09261e7fe48043a79/a6efce1b9d16fdfa68e14c42bd8f8c5495ee7b89.jpg
                title = HttpHelper.Jq(html, "threadTitle': '", "'").Replace("回复:", "");

                MatchCollection mc = new Regex(@"<img username.*?(https?://[^""]+)""/>", RegexOptions.Singleline).Matches(html);

                for (int i = 0; i < mc.Count; i++)
                {
                    Himgs.Add(mc[i].Groups[1].Value);
                }
                //https://gss0.bdstatic.com/6LZ1dD3d1sgCo2Kml5_Y_D3/sys/portrait/item/6465e58dabe7bb83e7949fe4b880e5a086e592af22d3?t=1531718435
                if (!((Content.Count == Authors.Count) && (Pids.Count == Authors.Count) && (Pids.Count == Himgs.Count) && (Uids.Count == Himgs.Count)))
                {
                    //int ssss = 0;
                    throw new Exception(this.tid + "title获取出现问题");
                }
                if (new Regex(@"comment_num&quot;:[1-9]\d{0,},").IsMatch(html))
                {
                    Lcid lcid = new Lcid();
                    try
                    {
                        // Common.Fid = "190294";
                        if (Common.Fid == null)
                        {
                            lcid = new Lcid(tid, HttpHelper.Jq(html, "fid:'", "'"), pn);
                        }
                        else
                        {
                            lcid = new Lcid(tid, Common.Fid, pn);
                        }
                    }
                    catch (Exception)
                    {
                    }

                    if (lcid.lun.Count > 0)
                    {
                        Content.AddRange(lcid.lcontent);
                        Authors.AddRange(lcid.lun);
                        Pids.AddRange(lcid.lcid);
                        //Times.AddRange(lcid.ltime);
                        Level.AddRange(lcid.llevel);
                        // Himgs.AddRange(lcid.lhimg);
                        Uids.AddRange(lcid.luid);
                    }
                }



                contentFilter();
            }
            //else
            //{
            //    if (maxPn == 0)
            //    {
            //        maxPn = 1;
            //    }
            //}http://tieba.baidu.com/p/291067672?pn=64905

            //}
            //catch (Exception)
            //{


            //}
        }
Exemple #2
0
        //private int pn;

        // private string tid;



        // private Lcid lcid;
        // public long t2;
        public ClientTit(string tid, int pn = 1)
        {
            string data = "_client_id=wappc_1568832181855_350&_client_type=2&_client_version=12.21.1.0&_phone_imei=fbce298035372371ff25decc0951c03&back=0&kz=" + tid + "&net_type=3&pn=" + pn + "&q_type=2&rn=30&with_floor=1";

            data = data + "&sign=" + HttpHelper.GetMD5HashFromFile(data.Replace("&", "") + "tiebaclient!!!");
            string res = HttpHelper.HttpPost(Conf.APP_URL + "/c/f/pb/page", data, null, null);

            //Pids.AddRange(HttpHelper.Jq(res, "\"pids\":\"", ",\"").Split(','));5803678320
            title = HttpHelper.Jq(res, "collect_mark_pid\":\"0\",\"title\":\"", "\"");
            if (title == null)
            {
                throw new Exception("获取标题错误,请检查帖子是否存在");
            }
            title = Regex.Unescape(title);
            maxPn = int.Parse(HttpHelper.Jq(res, "\"total_page\":\"", "\""));
            //  int indexsplit = res.IndexOf(",\"user_list\":[");
            MatchCollection mcs = new Regex(@"""id"":""([^""]+)"",""title"".+?""time"":""(\d+)"",""content"":\[(.*?)\],""lbs_info"".+?(\]|\}),""author_id"":""([^""""]+)""").Matches(HttpHelper.Jq(res, "\"post_list\":[", "],\"thread\":{"));
            MatchCollection mc1 = new Regex(@"""id"":""([^""]+)"",""portrait"":"".+?"",""name"":""([^""]*)"",""name_show"":""([^""]+)"",.+?""level_id"":""([^""]*)""").Matches(HttpHelper.Jq(res, "\"user_list\":[", "{\"id\":\"0\""));
            Dictionary <string, string[]> uidname = new Dictionary <string, string[]>();

            for (int i = 0; i < mc1.Count; i++)
            {
                if (mc1[i].Groups[4].Value == "")
                {
                    continue;
                }
                uidname.Add(mc1[i].Groups[1].Value, new string[] { mc1[i].Groups[2].Value, mc1[i].Groups[3].Value, mc1[i].Groups[4].Value });
            }

            for (int i = 0; i < mcs.Count; i++)
            {
                if (!uidname.ContainsKey(mcs[i].Groups[5].Value))
                {
                    continue;
                }
                Pids.Add(mcs[i].Groups[1].Value);
                Times.Add(mcs[i].Groups[2].Value);
                UnContent.Add(mcs[i].Groups[3].Value);
                Content.Add(Regex.Unescape(mcs[i].Groups[3].Value));
                Uids.Add(mcs[i].Groups[5].Value);
                string[] namelev = uidname[mcs[i].Groups[5].Value];
                Authors.Add(Regex.Unescape(namelev[0] == "" ? "昵称:" + namelev[1] : namelev[0]));
                // Himgs.Add("https://gss0.bdstatic.com/6LZ1dD3d1sgCo2Kml5_Y_D3/sys/portrait/item/" + mcs[i].Groups[5].Value);
                Level.Add(namelev[2]);
            }



            if (new Regex(@"sub_post_number"":""[1-9][^""]*""").IsMatch(res))
            {
                Lcid lcid = new Lcid();
                try
                {
                    // Common.Fid = "190294";
                    if (Common.Fid == null)
                    {
                        lcid = new Lcid(tid, HttpHelper.Jq(res, "forum\":{\"id\":\"", "\""), pn);
                    }
                    else
                    {
                        lcid = new Lcid(tid, Common.Fid, pn);
                    }
                }
                catch (Exception)
                {
                }

                if (lcid.lun.Count > 0)
                {
                    Content.AddRange(lcid.lcontent);
                    Authors.AddRange(lcid.lun);
                    Pids.AddRange(lcid.lcid);
                    Times.AddRange(lcid.ltime);
                    Level.AddRange(lcid.llevel);
                    //Himgs.AddRange(lcid.lhimg);
                    Uids.AddRange(lcid.luid);
                }
            }
            //  string res1 = "";

            /*
             * Authors.AddRange(HttpHelper.P_jq(res, "\",\"name\":\"","\"name_show"));
             *
             * Uids.AddRange(HttpHelper.P_jq(res, "\"author\":{\"id\":\"", "\", "));
             *
             * string[] hist = HttpHelper.P_jq(res, "\"portrait\":\"", "\", \"type");
             *
             * foreach (string item in hist)
             * {
             *  Himgs.Add("https://gss0.bdstatic.com/6LZ1dD3d1sgCo2Kml5_Y_D3/sys/portrait/item/" + item);
             * }
             * Level.AddRange(HttpHelper.P_jq(res, "\"level_id\":","\""));
             * //https://gss0.bdstatic.com/6LZ1dD3d1sgCo2Kml5_Y_D3/sys/portrait/item/
             */
            // GetHtml();
        }