/// <summary>
        /// 得到网页内容
        /// </summary>
        /// <param name="nextUrl"></param>
        /// <param name="postData"></param>
        /// <param name="cookies"></param>
        /// <param name="currentUrl"></param>
        /// <returns></returns>
        protected override string GetMainWebContent(string nextUrl, byte[] postData, ref string cookies, string currentUrl)
        {
            HttpHelper httpHelper = new HttpHelper
            {
                UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.108 Safari/537.36 2345Explorer/8.6.2.15784",
                Cookies   = _cookies
            };
            var webContent = httpHelper.GetHtmlByGet(nextUrl);

            //var webContent = base.GetMainWebContent(nextUrl, postData, ref _cookies, currentUrl);

            if (!Regex.Match(webContent, "^window.location.href='.*';").Success)
            {
                return(webContent);
            }



            Console.WriteLine(@"解析验证码中...................");
            bool isSuccess = false;
            int  i         = 1;

            while (isSuccess == false)
            {
                Console.WriteLine($"第{i}次解析验证码");
                TesseractDemo tesseract = new TesseractDemo();
                if ((isSuccess = tesseract.HandleValidateCode()) == false)
                {
                    i++;
                }
            }

            return(base.GetMainWebContent(nextUrl, postData, ref _cookies, currentUrl));
        }
Ejemplo n.º 2
0
        public bool CheckUserCode(string htmlStringContent)
        {
            const string shielded = "\"remind\"";

            if (htmlStringContent.Equals(shielded))
            {
                Console.WriteLine(@"解析验证码中...................");
                bool isSuccess = false;
                int  i         = 1;
                while (isSuccess == false)
                {
                    Console.WriteLine($"第{i}次解析验证码");
                    TesseractDemo tesseract = new TesseractDemo();
                    if ((isSuccess = tesseract.HandleValidateCode()) == false)
                    {
                        i++;
                    }
                }

                /*GetCourtTree1(caseType, level, key, span);
                 * return;*/
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理验证码
        /// </summary>
        public void LoopHandleValidateCode()
        {
            Console.WriteLine(@"解析验证码中...................");
            bool isSuccess = false;
            int  i         = 1;

            while (isSuccess == false)
            {
                Console.WriteLine($"第{i}次解析验证码");
                TesseractDemo tesseract = new TesseractDemo();
                if ((isSuccess = tesseract.HandleValidateCode()) == false)
                {
                    i++;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// GetHtmlByUrl
        /// </summary>
        /// <returns></returns>
        private string GetHtmlByUrl(UrlType urlType)
        {
            TesseractDemo tesseractDemo = new TesseractDemo();
            string        cookies;
            string        code = string.Empty;

            var    dic  = new Dictionary <string, string>();
            string html = string.Empty;

            if (urlType == UrlType.ZhiXing)
            {
                code    = tesseractDemo.GetValidateCodeByUrlExtend(_zhixingCaptchaUrl);
                cookies = tesseractDemo.Cookies;
                //这部分cookie要去掉才能显示正确的内容
                cookies = cookies.Replace(";Path=/search", "");
                dic.Add("selectCourtId", "1");
                dic.Add("selectCourtArrange", "1");
                dic.Add("searchCourtName", "全国法院(包含地方各级法院)");
                dic.Add("pname", _name);
                dic.Add("cardNum", _identifier);
                dic.Add("j_captcha", code.ToString());
                var postData = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);
                html = base.GetWebContent(_zhixingValidateUrl, postData, ref cookies);
            }
            else
            {
                var time = DateTime.Now;
                _shixinCaptchaUrl = $"{_shixinCaptchaUrl}?date={time}";



                code    = tesseractDemo.GetValidateCodeByUrlExtend(_shixinCaptchaUrl);
                cookies = tesseractDemo.Cookies;
                var times = 1;
                while (string.IsNullOrEmpty(cookies) || string.IsNullOrEmpty(code))
                {
                    times++;
                    if (times > 3)
                    {
                        return(_failInfo);
                        //throw new Exception("三次请求都没有得到cookies或者解析验证码出错!");
                    }
                    code    = tesseractDemo.GetValidateCodeByUrl(_shixinCaptchaUrl);
                    cookies = tesseractDemo.Cookies;
                }
                cookies = cookies.Replace("; Path=/", "");
                //cookies = tesseractDemo.Cookies;
                dic.Add("pProvince", "0");
                dic.Add("pName", _name);
                dic.Add("pCode", code.ToString());
                dic.Add("pCardNum", _identifier);
                var postData = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);


                html  = GetHtmlFaildReturnEmpty(_shixinValidateUrl, postData, cookies);
                times = 1;
                while (string.IsNullOrEmpty(html))
                {
                    times++;
                    if (times > 3)
                    {
                        return(_failInfo);
                        //throw new Exception("三次请求都没有得到网页内容!");
                    }
                    html = GetHtmlFaildReturnEmpty(_shixinValidateUrl, postData, cookies);
                }
            }

            return(html);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 得到案由搜索树
        /// </summary>
        /// <param name="caseType"></param>
        /// <param name="level"></param>
        /// <param name="key"></param>
        /// <param name="span"></param>
        public void GetReasonTree(string caseType, string level, string key, int span = 0)
        {
            //Console.WriteLine($"{new string(' ', span * 2)} {caseType} # {level} # {key}");

            var htmlString = GetHtmlFromPost(@"http://wenshu.court.gov.cn/List/ReasonTreeContent", Encoding.UTF8, $"Param=案件类型:{caseType},{level}:{key}&parval={key}");

            if (htmlString.Equals(string.Empty))
            {
                Console.WriteLine($"{caseType} # {key} # {level}(自己查)");
            }
            const string shielded = "\"remind\"";

            if (htmlString.Equals(shielded))
            {
                Console.WriteLine(@"解析验证码中...................");
                bool isSuccess = false;
                int  i         = 1;
                while (isSuccess == false)
                {
                    Console.WriteLine($"第{i}次解析验证码");
                    TesseractDemo tesseract = new TesseractDemo();
                    if ((isSuccess = tesseract.HandleValidateCode()) == false)
                    {
                        i++;
                    }
                }
                GetReasonTree(caseType, level, key, span);
                return;
            }

            var dics = GetSearchTreeKey(htmlString);

            if (dics.Count == 0)
            {
                var          postData          = $"Param=案件类型:{caseType},{level}:{key}&Index=1&Page=20&Order=裁判日期&Direction=asc";
                const string url               = "http://wenshu.court.gov.cn/List/ListContent";
                var          htmlStringContent = GetHtmlFromPost(url, Encoding.UTF8, postData);
                if (htmlStringContent.Equals(shielded))
                {
                    Console.WriteLine(@"解析验证码中...................");
                    bool isSuccess = false;
                    int  i         = 1;
                    while (isSuccess == false)
                    {
                        Console.WriteLine($"第{i}次解析验证码");
                        TesseractDemo tesseract = new TesseractDemo();
                        if ((isSuccess = tesseract.HandleValidateCode()) == false)
                        {
                            i++;
                        }
                    }
                    GetReasonTree(caseType, level, key, span);
                    return;
                }

                var num = GetTotalPages(htmlStringContent);
                Console.WriteLine($"{caseType} # {key} # {level}({num})");
                return;
            }

            foreach (var dic in dics)
            {
                if (dic.Key.Equals("人事争议") && dic.Value.Equals("四级案由"))
                {
                    Console.WriteLine($"{caseType} # {dic.Key} # {dic.Value}(手动查)");
                }
                else
                {
                    GetReasonTree(caseType, dic.Value, dic.Key, span + 1);
                }
            }
        }