示例#1
0
        public IPttRequest RequestWithCaptchaValue(IPttRequest request, IPttCaptcha pttCaptcha)
        {
            var htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(request.Response);

            var challengeField = htmlDoc.DocumentNode.SelectSingleNode("//input[@id='recaptcha_challenge_field']");
            if (challengeField == null)
            {
                return null;
            }
            var challengeFieldValue = challengeField.Attributes["value"].Value;

            var pttRequestFactory = new PttRequestFactory(request);
            var newReq = pttRequestFactory.Deserialize(string.Format("<Request><Url>{0}</Url><Method>POST</Method></Request>", request.Url));

            newReq.PostValue = string.Format("recaptcha_challenge_field={0}&recaptcha_response_field={1}&submit=I%27m+a+human", challengeFieldValue, pttCaptcha.Value ?? "");
            newReq.WrappedRequest.ContentType = "application/x-www-form-urlencoded";

            var pttResponse = new PttResponse();
            //bu gelen htmlsource dan textarea degerini oku
            htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(pttResponse.GetResponse(newReq));
            var valueToPasteNode = htmlDoc.DocumentNode.SelectSingleNode("//textarea");
            if (valueToPasteNode == null)
            {
                return null;
            }

            return null;
        }
示例#2
0
 public IPttRequest RequestWithCaptchaValue(IPttRequest request, IPttCaptcha pttCaptcha)
 {
     var pttRequestFactory = new PttRequestFactory(request);
     var newReq = pttRequestFactory.Deserialize(string.Format("<Request><Url>{0}</Url><Method>POST</Method><Referer>{0}</Referer></Request>", request.Url));
     newReq.WrappedRequest.ContentType = "application/x-www-form-urlencoded";
     newReq.PostValue = Regex.Replace(request.PostValue, @"packageSearchCaptcha=[^&]*&", "packageSearchCaptcha=" + pttCaptcha.Value + "&");
     return newReq;
 }
示例#3
0
        public IPttRequest RequestWithCaptchaValue(IPttRequest request, IPttCaptcha pttCaptcha)
        {
            var pttRequestFactory = new PttRequestFactory(request);
            var newReq = pttRequestFactory.Deserialize(string.Format("<Request><Url>{0}</Url><Method>POST</Method></Request>", request.Url));

            newReq.PostValue = "samo_action=antibot&are_you_human=" + pttCaptcha.Value;
            newReq.WrappedRequest.ContentType = "application/x-www-form-urlencoded";
            return newReq;
        }
 protected Tuple<string, string> ResolveCaptcha(IPttRequest request, IPttCaptcha captcha, int captchaTries)
 {
     var captchaFileName = DownloadCaptchaImage(request, captcha);
     var captchaValue = _captchaBreaker.Guess(captchaFileName, captchaTries);
     return new Tuple<string, string>(captchaValue, captchaFileName);
 }
        protected string DownloadCaptchaImage(IPttRequest request, IPttCaptcha captcha)
        {
            CaptchaHelper.CreateCaptchasFolder();
            var captchaFileName = CaptchaHelper.NewCaptchaFileName();
            //Logger.LogProcess("gelen captcha dosya adi:" + captchaFileName);
            var captchaImageBytes = captcha.IsBase64 ? Convert.FromBase64String(captcha.Base64Content) : CaptchaImageBytes(request, captcha.Url);

            var fs = new FileStream(captchaFileName, FileMode.Create);
            var bw = new BinaryWriter(fs);
            bw.Write(captchaImageBytes);
            fs.Close();
            bw.Close();
            return captchaFileName;
        }
示例#6
0
        public IPttRequest RequestWithCaptchaValue(IPttRequest request, IPttCaptcha pttCaptcha)
        {
            if (_extensiveLoggingNeeded)
            {
                Logger.LogProcess("TezCaptcha RequestWithCaptchaValue captcha coming:" + pttCaptcha.ToString());
            }

            var pttRequestFactory = new PttRequestFactory(request);
            var newRequest = pttRequestFactory.Deserialize(
                string.Format("<Request><Url>{0}</Url><Referer>{1}</Referer><Method>POST</Method></Request>",
                    "http://www.tez-tour.com/captcha/check.htm",
                    "http://www.tez-tour.com/captcha/index.htm?locale=ru&pr=s&ref=http://www.tez-tour.com/search.html"
                    ));

            newRequest.WrappedRequest.AllowAutoRedirect = false;
            newRequest.WrappedRequest.Timeout = newRequest.WrappedRequest.Timeout * 4;
            newRequest.WrappedRequest.ReadWriteTimeout = newRequest.WrappedRequest.ReadWriteTimeout * 4;
            newRequest.WrappedRequest.ServicePoint.ConnectionLeaseTimeout = newRequest.WrappedRequest.Timeout;
            newRequest.WrappedRequest.ServicePoint.MaxIdleTime = newRequest.WrappedRequest.Timeout;

            var captchaImageUri = new Uri(pttCaptcha.Url);
            var captchaFileNameWithExtension = Path.GetFileNameWithoutExtension(captchaImageUri.AbsolutePath);

            var captchaUrl = pttCaptcha.FormUrl;
            var hashStart = captchaUrl.IndexOf("#");
            if (hashStart > -1) captchaUrl = captchaUrl.Substring(hashStart);
            captchaUrl = HttpUtility.UrlEncode(HttpUtility.UrlEncode(captchaUrl));

            if (_extensiveLoggingNeeded)
            {
                Logger.LogProcess("TezCaptcha RequestWithCaptchaValue captchaurl parsed:" + captchaUrl);
            }

            newRequest.PostValue = string.Format("image={0}&ref={3}&pr=s&hashRef={2}&answer={1}&submit=%D0%AF+%D0%BD%D0%B5+%D1%80%D0%BE%D0%B1%D0%BE%D1%82%21",
                captchaFileNameWithExtension,
                pttCaptcha.Value,
                captchaUrl,
                "http%3A%2F%2Fwww.tez-tour.com%2Fsearch.html");

            newRequest.WrappedRequest.ContentType = "application/x-www-form-urlencoded";

            return newRequest;
        }