Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string GetReCaptchaResponse(bool noScriptUrl)
- {
- if (string.IsNullOrEmpty(siteSource)) return null;
- // Sprawdź czy trzeba rozwiązać ReCaptche
- bool isReCaptchaAvailable = (siteSource.Contains("recaptcha_response_field") && siteSource.Contains("recaptcha_challenge_field"));
- string recaptchaResponseField;
- if (isReCaptchaAvailable)
- {
- // Wyłuskaj klucz publiczny
- string publicKey = Regex.Match(siteSource, "challenge\\?k=(?<publicKey>[^\"']+)").Groups["publicKey"].Value.Trim();
- if (string.IsNullOrEmpty(publicKey)) return null;
- string recaptchaSrc = string.Empty;
- if (noScriptUrl)
- recaptchaSrc = webHelper.DownloadStuff(ChallengeNoScriptUrl + publicKey);
- else
- recaptchaSrc = webHelper.DownloadStuff(ChallengeUrl + publicKey);
- // Wyłuskaj kod 'challenge', który posłuży do wczytania obrazka
- string recaptchaChallengeField = string.Empty;
- if (!noScriptUrl)
- {
- recaptchaChallengeField =
- Challenge =
- Regex.Match(recaptchaSrc, "challenge : '(?<challenge>[^']+)'\\,").Groups["challenge"].Value.Trim
- ();
- if (string.IsNullOrEmpty(recaptchaChallengeField)) return null;
- }
- string recaptchaImageUrl = string.Empty;
- if (noScriptUrl)
- {
- this.Challenge =
- Regex.Match(recaptchaSrc, "image\\?c\\=(?<challenge>[^\"]+)").Groups["challenge"].Value;
- recaptchaImageUrl = ImageUrl
- + this.Challenge;
- }
- else
- recaptchaImageUrl = ImageUrl + recaptchaChallengeField;
- // Pobierz obrazek
- Image recaptchaImage = Image.FromStream(new MemoryStream(webHelper.DownloadData(recaptchaImageUrl)));
- if (recaptchaImage.Width == 0) return null;
- FormLoginCaptcha captchaForm = new FormLoginCaptcha(recaptchaImage, siteBriefDescription);
- captchaForm.ShowDialog();
- recaptchaResponseField = captchaForm.GetCaptchaText();
- }
- else return null;
- return recaptchaResponseField;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement