Exemple #1
0
        /*Retorna o html de uma página passando pelo captcha é preciso passar o link da imagem
         * o linksite é concatenado ao texto retirado da imagem linksite + captcharesolvido*/
        internal static HtmlDocument GetHtmlHandleCaptcha(string linksite, Encoding e, string captchaParameter, string capthcaLink = "", NameValueCollection formparameters = null, string metodo = "POST")
        {
            DeathByCaptcha.Client objSocketClient;
            try
            {
                objSocketClient = new DeathByCaptcha.SocketClient(CaptchaUser, CaptchaPass);
            }
            catch (Exception ex)
            {
                RService.Log("RService Exception WebHandle: (SocketClient)" + ex.Message + " / " + ex.StackTrace + " / " + ex.InnerException + " at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                return(null);
            }
            DeathByCaptcha.Captcha objCaptcha;
            HtmlDocument           htmlDoc = new HtmlDocument();

            RService.Log("RService WebHandle: (Linha 90) at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
            if (formparameters == null)
            {
                formparameters = new NameValueCollection();
            }
            int number = 0;

            while (number < 2)
            {
                try
                {
                    ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(CustomValidation);

                    using (CookieAwareWebClient wc = new CookieAwareWebClient())
                        using (MemoryStream ms = new MemoryStream(wc.DownloadData(capthcaLink)))
                        {
                            RService.Log("RService WebHandle: (Linha 103) at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                            RService.Log("RService WebHandle [MemoryStream Length: " + ms.Length + "] [CapthcaLink: " + capthcaLink + "]: (Linha 104) at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                            objCaptcha = objSocketClient.Decode(ms, 120);
                            if (objCaptcha.Solved && objCaptcha.Correct)
                            {
                                RService.Log("RService WebHandle: (Linha 108) at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                                objSocketClient.Close();

                                formparameters[captchaParameter] = objCaptcha.Text;

                                htmlDoc.LoadHtml(HttpUtility.HtmlDecode(e.GetString(wc.UploadValues(linksite, metodo, formparameters))));
                                RService.Log("RService WebHandle: (Linha 111) at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                            }
                        }
                    break;
                }
                catch (Exception ex)
                {
                    RService.Log("RService Exception WebHandle: (GetHtmlHandleCaptcha)" + ex.Message + " / " + ex.StackTrace + " / " + ex.InnerException + " at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                    Thread.Sleep(1000 * 10);
                    objSocketClient = new DeathByCaptcha.SocketClient(CaptchaUser, CaptchaPass);
                    number++;
                }
            }
            return(number == 2 ? null : htmlDoc);
        }
Exemple #2
0
        /*Resolve captcha usando api DeathByCaptcha*/
        internal static string ResolveCaptcha(string file)
        {
            string solution = string.Empty;

            DeathByCaptcha.Client objSocketClient;
            try
            {
                objSocketClient = new DeathByCaptcha.SocketClient(CaptchaUser, CaptchaPass);
            }
            catch (Exception e)
            {
                RService.Log("Exception WebHandle: (ResolveCaptcha)" + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                return(null);
            }
            DeathByCaptcha.Captcha objCaptcha;
            int number = 0;

            while (number < 2)
            {
                try
                {
                    using (FileStream f = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
                        objCaptcha = objSocketClient.Decode(f, 120);
                        if (objCaptcha.Solved && objCaptcha.Correct)
                        {
                            objSocketClient.Close();
                            solution = objCaptcha.Text;
                        }
                    }

                    break;
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000 * 5);
                    objSocketClient = new DeathByCaptcha.SocketClient(CaptchaUser, CaptchaPass);
                    number++;

                    RService.Log("Exception WebHandle: (ResolveCaptcha)" + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + "RSERVICE" + ".txt");
                }
            }
            return(number == 2 ? null : solution);
        }