Exemple #1
0
        private async Task <SolveResult> SolveCaptchaChallenge(DetectResult?captchaDetectResult = null)
        {
            var result = default(SolveResult);

            if (!CaptchaSolvingEnabled)
            {
                return(result);
            }

            if (!captchaDetectResult.HasValue)
            {
                captchaDetectResult = await CloudflareDetector.Detect(httpClient, siteUrl);

                siteUrl = ChangeUrlScheme(siteUrl, captchaDetectResult.Value.SupportsHttp);
            }

            var exceptional = IsExceptionalDetectionResult(captchaDetectResult.Value);

            if (exceptional.Item1)
            {
                result = exceptional.Item2;
            }
            else if (captchaDetectResult.Value.Protection.Equals(CloudflareProtection.Captcha))
            {
                result = await new CaptchaChallengeSolver(httpClient, cloudflareHandler, siteUrl, captchaDetectResult.Value, userAgent, captchaProvider)
                         .Solve();
            }
            else if (captchaDetectResult.Value.Protection.Equals(CloudflareProtection.JavaScript))
            {
                result = await SolveJavascriptChallenge(captchaDetectResult);
            }

            return(result);
        }
Exemple #2
0
        private async Task <SolveResult> SolveJavascriptChallenge(DetectResult?jsDetectResult = null)
        {
            var result = default(SolveResult);

            if (!jsDetectResult.HasValue)
            {
                jsDetectResult = await CloudflareDetector.Detect(httpClient, siteUrl);

                siteUrl = ChangeUrlScheme(siteUrl, jsDetectResult.Value.SupportsHttp);
            }

            var exceptional = IsExceptionalDetectionResult(jsDetectResult.Value);

            if (exceptional.Item1)
            {
                result = exceptional.Item2;
            }
            else if (jsDetectResult.Value.Protection.Equals(CloudflareProtection.JavaScript))
            {
                result = await new JsChallengeSolver(httpClient, cloudflareHandler, siteUrl, jsDetectResult.Value, userAgent, ClearanceDelay)
                         .Solve();
            }

            if (!result.Success && result.NewDetectResult.HasValue && result.NewDetectResult.Value.Protection.Equals(CloudflareProtection.Captcha))
            {
                captchaDetectResults.Add(result.NewDetectResult.Value);
            }

            return(result);
        }