Exemplo n.º 1
0
        public override string GetHtml(IPttRequest request, bool forHotelList)
        {
            if (_extensiveLoggingNeeded)
            {
                Logger.LogProcess("RequestResponseWithCaptcha gethtml coming request: " + request);
            }
            IPttResponse response = new PttResponse();
            var htmlSource = response.GetResponse(request);
            if(_extensiveLoggingNeeded)
            {
                Logger.LogProcess("RequestResponseWithCaptcha gethtml: "+ htmlSource);
            }
            if (!_captchaRequestResponse.CaptchaShown(htmlSource))
            {
                if (_extensiveLoggingNeeded)
                {
                    Logger.LogProcess("RequestResponseWithCaptcha captcha not shown, returning");
                }

                return htmlSource;
            }

            if (_extensiveLoggingNeeded)
            {
                Logger.LogProcess("RequestResponseWithCaptcha captcha shown");
            }
            return CaptchaPassedResult(request, htmlSource);
        }
Exemplo n.º 2
0
 public static string CurlSimple(string url, string contentType = "text/html", IWebProxy proxy = null, CookieContainer cookieContainer = null)
 {
     try
     {
         PttRequestFactory requestFactory = null;
         requestFactory = proxy != null ? new PttRequestFactory(proxy, cookieContainer) : new PttRequestFactory();
         var pttRequest = requestFactory.SimpleRequest(url, contentType);
         var response = new PttResponse();
         return response.GetResponse(pttRequest);
     }
     catch (Exception exception)
     {
         Logger.LogExceptions(exception);
     }
     return null;
 }
Exemplo n.º 3
0
 public static string CurlSimplePost(string url, string postData, string host, bool chunked = false)
 {
     try
     {
         var pttRequestFactory = new PttRequestFactory();
         var pttRequest = pttRequestFactory.SimpleRequest(url);
         pttRequest.Chunked = chunked;
         pttRequest.WrappedRequest.Host = host;
         pttRequest.WrappedRequest.Method = "POST";
         pttRequest.WrappedRequest.ContentType = "application/x-www-form-urlencoded";
         pttRequest.PostValue = postData;
         var pttResponse = new PttResponse();
         return pttResponse.GetResponse(pttRequest);
     }
     catch (Exception exception)
     {
         Logger.LogExceptions(exception);
     }
     return null;
 }
Exemplo n.º 4
0
 public virtual string GetHtml(IPttRequest request, bool forHotelList)
 {
     IPttResponse response = new PttResponse();
     var htmlSource = response.GetResponse(request);
     return htmlSource;
 }
Exemplo n.º 5
0
        protected string CaptchaPassedResult(IPttRequest request, string htmlSource)
        {
            IPttResponse response = new PttResponse();
            var html = htmlSource;
            var captchaTries = 1;
            while (true)
            {
                var pttCaptcha = _captchaRequestResponse.CaptchaImage(request, html);

                if (_extensiveLoggingNeeded)
                {
                    Logger.LogProcess("RequestResponseWithCaptcha CaptchaPassedResult coming captcha:"+ pttCaptcha);
                }

                try
                {
                    var captchaResolve = ResolveCaptcha(request, pttCaptcha, captchaTries);
                    pttCaptcha.Value = captchaResolve.Item1;
                    pttCaptcha.FileNameInTempDir = captchaResolve.Item2;

                    if (_extensiveLoggingNeeded)
                    {
                        Logger.LogProcess("RequestResponseWithCaptcha CaptchaPassedResult after resolving:" + pttCaptcha);
                    }

                }
                catch (Exception exc)
                {
                    Logger.LogExceptions(exc);
                    return null;
                }
                IPttRequest captchaAddedRequest = _captchaRequestResponse.RequestWithCaptchaValue(request, pttCaptcha);
                if(_extensiveLoggingNeeded)
                {
                    Logger.LogProcess("RequestResponseWithCaptcha CaptchaPassedResult captchaAddedRequest:"+captchaAddedRequest);
                }
                var captchaPassedResult = response.GetResponse(captchaAddedRequest);
                captchaAddedRequest.WrappedRequest = null;
                GC.Collect();

                if (_extensiveLoggingNeeded)
                {
                    Logger.LogProcess("RequestResponseWithCaptcha CaptchaPassedResult captchaPassedResult:" + captchaPassedResult);
                }
                if (_captchaRequestResponse.RepeatFirstRequest)
                {
                    var pttRequestFactory = new PttRequestFactory(request);
                    var firstRequest = pttRequestFactory.Deserialize(string.Format("<Request><Url>{0}</Url><Host>www.tez-tour.com</Host><Referer> <![CDATA[http://www.tez-tour.com]]></Referer></Request>", request.Url));

                    if (_extensiveLoggingNeeded)
                    {
                        Logger.LogProcess("RequestResponseWithCaptcha CaptchaPassedResult RepeatFirstRequest firstrequest:" + firstRequest);
                    }
                    captchaPassedResult = response.GetResponse(firstRequest);
                }

                if (_captchaRequestResponse.CaptchaShown(captchaPassedResult))
                {
                    Logger.LogProcess(string.Format("Incorrect captcha for {0}", pttCaptcha.FileNameInTempDir));
                    html = captchaPassedResult;
                    captchaTries++;
                    continue;
                }
                Logger.LogProcess(string.Format("Correct captcha for {0}", pttCaptcha.FileNameInTempDir));

                return captchaPassedResult;
            }
        }
Exemplo n.º 6
0
 protected byte[] CaptchaImageBytes(IPttRequest request, string imageSource)
 {
     IPttRequestFactory pttRequestFactory = new PttRequestFactory(request, false);
     IPttResponse response = new PttResponse();
     return response.GetResponseBytes(pttRequestFactory.SimpleRequest(imageSource));
 }
Exemplo n.º 7
0
        private static void SetupProxy()
        {
            var proxyUserName = ConfigurationManager.AppSettings["proxyUserName"];
            var proxyPassword = ConfigurationManager.AppSettings["proxyPassword"];

            if (string.IsNullOrEmpty(proxyUserName) || string.IsNullOrEmpty(proxyPassword)) return;
            try
            {
                var pttRequestFactory = new PttRequestFactory();
                var pttRequest = pttRequestFactory.SimpleRequest("http://vip.squidproxies.com/valid.php");
                pttRequest.WrappedRequest.Host = "vip.squidproxies.com";
                pttRequest.WrappedRequest.Method = "POST";
                pttRequest.WrappedRequest.ContentType = "application/x-www-form-urlencoded";
                pttRequest.PostValue = "username="******"&password="******"&button=Sign+In";
                var pttResponse = new PttResponse();
                pttResponse.GetResponse(pttRequest);

                var secondPttRequest = pttRequestFactory.SimpleRequest("http://vip.squidproxies.com/index.php?action=authips");
                secondPttRequest.WrappedRequest.Host = "vip.squidproxies.com";
                secondPttRequest.WrappedRequest.Referer = "http://vip.squidproxies.com/index.php?action=assignedproxies";
                pttRequest.CopySession(secondPttRequest);
                pttResponse.GetResponse(secondPttRequest);

                //check if ip is in the list
                var document = new HtmlDocument();
                document.LoadHtml(secondPttRequest.Response);
                var ipNode = document.DocumentNode.SelectSingleNode("//div[@class='bcont']");
                if (ipNode == null || ipNode.FirstChild == null) return;
                var ipText = ipNode.FirstChild.InnerText.Trim(); //Your IP: 88.103.5.212;
                var words = ipText.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                var ipaddress = words.Last();
                Logger.LogProcess("IP specified in squid proxy page: "+ipaddress);
                var ipListNode = ipNode.SelectSingleNode("//textarea[@name='authips']");
                if (ipListNode == null) return;
                var ipList = ipListNode.InnerText;
                var ips = ipList.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (ips.Contains(ipaddress)) return;

                var thirdPttRequest = pttRequestFactory.SimpleRequest("http://vip.squidproxies.com/index.php?action=addauthip");
                thirdPttRequest.WrappedRequest.Host = "vip.squidproxies.com";
                thirdPttRequest.WrappedRequest.Referer = "http://vip.squidproxies.com/index.php?action=addauthip";
                secondPttRequest.CopySession(thirdPttRequest);
                pttResponse.GetResponse(thirdPttRequest);
                Thread.Sleep(60000);

            }
            catch (Exception exception)
            {
                Logger.LogExceptions(exception);
            }
        }