/// <summary>
        /// 定义第一个链接,案件类型:刑事案件,法院地域:北京市,裁判年份:2016
        /// </summary>
        /// <param name="param">案件类型[刑事案件,民事案件,行政案件,赔偿案件,执行案件]</param>
        /// <returns></returns>
        protected override string InitFirstUrl(FaYuanParameter param)
        {
            IDictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("Param", $"案件类型:{param.Reason},法院地域:{param.Court},裁判年份:{param.Year}");
            dic.Add("Page", "20");
            dic.Add("Order", "裁判日期");
            dic.Add("Index", "1");
            dic.Add("Direction", "asc");

            var postData = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);

            var cookies    = string.Empty;
            var htmlString = base.GetMainWebContent(HomePage, postData, ref cookies, HomePage);

            //var htmlString = GetHtmlFromPost(HomePage, Encoding.UTF8,$"Param=案件类型:{param.Keyword}&Page=20&Order=法院层级&Index=1&Direction=asc");

            _pageInfo = new PageInfo
            {
                Index      = 1,
                CaseType   = param.Reason,
                Area       = param.Court,
                Year       = param.Year,
                Page       = 20,
                TotalPages = GetTotalPages(htmlString)
            };
            _pageInfo.TotalIndex = _pageInfo.TotalPages / _pageInfo.Page;

            Console.WriteLine($"总共页数:{_pageInfo.TotalIndex}");


            return(HomePage);
        }
 /// <summary>
 /// InitPostDataQueue
 /// </summary>
 /// <param name="infoDic"></param>
 private void InitPostDataQueue(Dictionary <string, string> infoDic)
 {
     for (var i = 0; i < _totalPage; i++)
     {
         infoDic["page"] = $"{i} + 1";
         var postDataCur = WebRequestCtrl.BuildPostDatas(infoDic, Encoding.UTF8);
         _postDataQueue.Enqueue(Encoding.Default.GetString(postDataCur));
     }
 }
Esempio n. 3
0
        /// <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)
        {
            IDictionary <string, string> dic = new Dictionary <string, string>();

            var paramString = $"案件类型:{_pageInfo.CaseType}";

            if (!string.IsNullOrEmpty(_pageInfo.ReasonLevel) && !string.IsNullOrEmpty(_pageInfo.ReasonKey))
            {
                paramString = $"{paramString},{_pageInfo.ReasonLevel}:{_pageInfo.ReasonKey}";
            }
            if (!string.IsNullOrEmpty(_pageInfo.CourtLevel) && !string.IsNullOrEmpty(_pageInfo.CourtKey))
            {
                paramString = $"{paramString},{_pageInfo.CourtLevel}:{_pageInfo.CourtKey}";
            }
            if (!string.IsNullOrEmpty(_pageInfo.Year))
            {
                paramString = $"{paramString},裁判年份:{_pageInfo.Year}";
            }
            if (_pageInfo.CourtLevel.Equals("法院地域"))
            {
                paramString = $"{paramString},法院层级:高级法院";
            }

            dic.Add("Param", paramString);
            dic.Add("Page", "20");
            dic.Add("Order", "裁判日期");

            if (_pageInfo.Index <= _pageInfo.MaxIndex)
            {
                dic.Add("Index", $"{_pageInfo.Index}");
                dic.Add("Direction", "asc");
            }
            else
            {
                dic.Add("Index", $"{_pageInfo.Index - _pageInfo.MaxIndex}");
                dic.Add("Direction", "desc");
            }

            var postDataCur = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);

            var htmlString = base.GetMainWebContent(HomePage, postDataCur, ref cookies, HomePage);


            const string shielded = "\"remind\"";

            if (!htmlString.Equals(shielded))
            {
                return(htmlString);
            }
            //等于指定字符串,则处理验证码
            this.LoopHandleValidateCode();

            return(base.GetMainWebContent(HomePage, postDataCur, ref cookies, HomePage));
        }
Esempio n. 4
0
        /// <summary>
        /// 验证验证码
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private bool VerificationCode(string code, string name)
        {
            IDictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("verifyCode", code);
            dic.Add("name", name);
            var postData = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);

            var htmlString = base.GetWebContent("http://gsxt.zjaic.gov.cn/search/doValidatorVerifyCode.do", postData,
                                                ref _cookies, "http://gsxt.zjaic.gov.cn/search/doEnGeneralQueryPage.do", true);

            var value = Regex.Match(htmlString, "(?<=\"message\":\").*?(?=\")").Value;

            return(value.Equals("true"));
        }
Esempio n. 5
0
        /// <summary>
        /// GetCorpid
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        private void GetCorpid(string code, string name)
        {
            IDictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("clickType", "1");
            dic.Add("verifyCode", code);
            dic.Add("name", name);

            var postData = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);

            var htmlString = base.GetWebContent("http://gsxt.zjaic.gov.cn/search/doGetAppSearchResult.do", postData,
                                                ref _cookies, "http://gsxt.zjaic.gov.cn/search/doEnGeneralQueryPage.do", false);


            _corpid = Regex.Match(htmlString, @"(?<=href=""/appbasicinfo/doViewAppBasicInfoByLog\.do\?corpid=).*(?="")").Value;
        }
        /// <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)
        {
            IDictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("Param", $"案件类型:{_pageInfo.CaseType},法院地域:{_pageInfo.Area},裁判年份:{_pageInfo.Year}");
            dic.Add("Page", "20");
            dic.Add("Order", "法院层级");
            dic.Add("Index", $"{_pageInfo.Index}");
            dic.Add("Direction", "asc");

            var postDataCur = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);


            return(base.GetMainWebContent(HomePage, postDataCur, ref cookies, HomePage));

            //return GetHtmlFromPost(HomePage, Encoding.UTF8, $"Param=案件类型:{_pageInfo.Reason}&Page=20&Order=法院层级&Index={_pageInfo.Index}&Direction=asc");
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        /// <summary>
        /// 定义第一个链接,案件类型:刑事案件,法院地域:北京市,裁判年份:2016
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        protected override string InitFirstUrl(FaYuanParameter param)
        {
            var paramDic = GetParam(param);

            //案件类型:民事案件,四级案由:遗嘱继承纠纷,中级法院:北京市第一中级人民法院,裁判年份:2016
            IDictionary <string, string> dic = new Dictionary <string, string>();
            var paramString = $"案件类型:{paramDic["CaseType"]}";

            if (!string.IsNullOrEmpty(paramDic["ReasonLevel"]) && !string.IsNullOrEmpty(paramDic["ReasonKey"]))
            {
                paramString = $"{paramString},{paramDic["ReasonLevel"]}:{paramDic["ReasonKey"]}";
            }
            if (!string.IsNullOrEmpty(paramDic["CourtLevel"]) && !string.IsNullOrEmpty(paramDic["CourtKey"]))
            {
                paramString = $"{paramString},{paramDic["CourtLevel"]}:{paramDic["CourtKey"]}";
            }
            if (!string.IsNullOrEmpty(paramDic["Year"]))
            {
                paramString = $"{paramString},裁判年份:{paramDic["Year"]}";
            }
            if (paramDic["CourtLevel"].Equals("法院地域"))
            {
                paramString = $"{paramString},法院层级:高级法院";
            }

            dic.Add("Param", paramString);
            dic.Add("Page", "20");
            dic.Add("Order", "裁判日期");
            dic.Add("Index", "1");
            dic.Add("Direction", "asc");

            var postData = WebRequestCtrl.BuildPostDatas(dic, Encoding.UTF8);

            var cookies    = string.Empty;
            var htmlString = base.GetMainWebContent(HomePage, postData, ref cookies, HomePage);

            //处理验证码
            const string shielded = "\"remind\"";

            if (htmlString.Equals(shielded))
            {
                //循环处理验证码,直到验证通过
                this.LoopHandleValidateCode();
                //处理完了重新来
                htmlString = base.GetMainWebContent(HomePage, postData, ref cookies, HomePage);
            }

            //设置参数
            _pageInfo = new PageInfo
            {
                Index       = 1,
                CaseType    = paramDic["CaseType"],
                ReasonLevel = paramDic["ReasonLevel"],
                ReasonKey   = paramDic["ReasonKey"],
                CourtLevel  = paramDic["CourtLevel"],
                CourtKey    = paramDic["CourtKey"],
                Year        = paramDic["Year"],
                Page        = 20,
                TotalPages  = GetTotalPages(htmlString),
            };
            _pageInfo.TotalIndex    = (_pageInfo.TotalPages / _pageInfo.Page) + (_pageInfo.TotalPages % _pageInfo.Page == 0?0:1);
            _pageInfo.ActuallyIndex = _pageInfo.TotalIndex > 2 * _pageInfo.MaxIndex ? 2 * _pageInfo.MaxIndex : _pageInfo.TotalIndex;


            return(HomePage);
        }