public List <VkUser> GetFriendsListForInventation(string eventId, BackgroundWorker bw = null) { Logger.LogMethod(); List <VkUser> vkUsersInTheGroupTotal = new List <VkUser>(); List <VkUser> vkUsersInTheGroupSubSet; int offset = 0; decimal workProgerss = 0m; do { string url = string.Format("{0}friends", HttpConnector.HTTPVKCOM); Thread.Sleep(HttpConnector.TIMEOUT); HttpWebResponseEx resp = HttpConnector.SendHttpWebRequestAndGetResponse(url, HttpMethod.POST, requestBody: string.Format("act=get_section_friends&al=1&gid={0}&offset={1}§ion=members&sugg_rev=0", eventId, offset)); string responseString = resp.ResponseText; vkUsersInTheGroupSubSet = VkUserEx.ParseFriendsList(responseString); offset += vkUsersInTheGroupSubSet.Count; vkUsersInTheGroupTotal.AddRange(vkUsersInTheGroupSubSet); workProgerss += 0.25m; if (bw != null) { bw.ReportProgress((int)workProgerss); } } while (vkUsersInTheGroupSubSet.Count != 0); return(vkUsersInTheGroupTotal); }
public static string GetGroupIdByUrl(string url) { Logger.LogMethod(); HttpWebResponseEx resp = HttpConnector.SendHttpWebRequestAndGetResponse(url, HttpMethod.GET); string responseString = resp.ResponseText; //<a href="/audios-65378758" onclick="return nav.go(this, event);" class="module_header"> string pattern = @"<a href=""/audios-(\d*)"" onclick=""return nav.go\(this, event\);"" class=""module_header"">"; string groupId = Regex.Matches(responseString, pattern, RegexOptions.Singleline)[0].Groups[1].Value; return(groupId); }
public List <VkUser> GetAllUsersInCity(string groupId, string countryId, string cityId, BackgroundWorker bw = null) { Logger.LogMethod(groupId, countryId, cityId, bw); AlSearchEngine alSearchEngine = new AlSearchEngine(); int totalUserCount = 0; List <VkUser> vkUsersInTheCity = new List <VkUser>(); List <VkUser> vkUsersSubset; string baseUrl = string.Format("{0}al_search.php", HttpConnector.HTTPVKCOM); int offset; bool hasMore; string postBody; do { offset = 0; hasMore = false; do { postBody = string.Format("al=1&c%5Bcity%5D={0}&c%5Bcountry%5D={1}&c%5Bgroup%5D={2}&c%5Bname%5D=1&c%5Bphoto%5D=1&c%5Bsection%5D=people", cityId, countryId, groupId) + alSearchEngine.GetSearchUrlAddition(offset); Thread.Sleep(HttpConnector.TIMEOUT); HttpWebResponseEx resp = HttpConnector.SendHttpWebRequestAndGetResponse(baseUrl, HttpMethod.POST, requestBody: postBody); string responseString = resp.ResponseText; if (alSearchEngine.IsFirstStep() && (offset == 0)) { totalUserCount = VkUserEx.AlSearchGetSummaryUserCount(responseString); } if (totalUserCount == 0) { break; } vkUsersSubset = VkUserEx.AlSearchParsePeopleRow(responseString); vkUsersInTheCity = vkUsersInTheCity.Union(vkUsersSubset, new VkUserComparer()).ToList(); hasMore = VkUserEx.AlSearchParseHasMore(responseString); offset = VkUserEx.AlSearchParseOffset(responseString); if (bw != null) { bw.ReportProgress(vkUsersInTheCity.Count * 100 / totalUserCount); } } while (hasMore && offset > 0 && offset < 1000); } while (alSearchEngine.NextStep(offset)); vkUsersInTheCity.SetCityIdToAllUsers(cityId); List <VkUser> allUsers = new List <VkUser>(); allUsers.AddRange(vkUsersInTheCity); return(allUsers); }
public KeyValuePair <string, string> ParseInviteAnswer(string responseString) { Logger.LogMethod(); string valueStr = string.Empty; //<!--14692<!><!>0<!>6524<!>0<!><!int>0<!>Пользователь запретил приглашать себя на встречи. //<!--14692<!><!>0<!>6524<!>2<!>799332814008<!>0 //<!--14692<!><!>0<!>6524<!>8<!>Ошибка доступа<!><!>3386884 string patternAnsw = @"<!--\d*<!><!>\d*<!>\d*<!>(\d*)<!>(.*)"; string patternCaptcha = @"(\d+)<!>\d*"; string patternResult = @"<!int>\d+<!>(.*)"; string patternAccessError = @"([^<>]*)<!><!>\d*"; if (responseString == "The remote server returned an error: (501) Not Implemented.") { return(new KeyValuePair <string, string>("501", "The remote server returned an error: (501) Not Implemented.")); } MatchCollection mcResult = Regex.Matches(responseString, patternAnsw); MatchCollection mcSubResult; switch (mcResult[0].Groups[1].Value) { case InivteAnswerCodes.InivteWasSent: mcSubResult = Regex.Matches(mcResult[0].Groups[2].Value, patternResult); valueStr = mcSubResult[0].Groups[1].Value; break; case InivteAnswerCodes.AccessError: mcSubResult = Regex.Matches(mcResult[0].Groups[2].Value, patternAccessError); Logon(); break; case InivteAnswerCodes.CaptchaEnter: mcSubResult = Regex.Matches(mcResult[0].Groups[2].Value, patternCaptcha); string captchaSid = mcSubResult[0].Groups[1].Value; if (captchaSid != string.Empty) { string url = string.Format("{0}captcha.php?sid={1}&s=1", HttpConnector.HTTPVKCOM, captchaSid); HttpWebResponseEx resp = HttpConnector.SendHttpWebRequestAndGetResponse(url, HttpMethod.GET, withoutLogging: true); System.IO.Stream responseStream = resp.HttpWebResponse.GetResponseStream(); Bitmap bitmap = new Bitmap(responseStream); CaptchaForm captchaForm = new CaptchaForm(bitmap); CaptchaContainer.Key = string.Empty; while (CaptchaContainer.Key == string.Empty) { captchaForm.ShowDialog(); } valueStr = string.Format("&captcha_key={0}&captcha_sid={1}", CaptchaContainer.Key, captchaSid); } break; default: throw new ArgumentException(); } return(new KeyValuePair <string, string>(mcResult[0].Groups[1].Value, valueStr)); }
public static HttpWebResponseEx SendHttpWebRequestAndGetResponse( string url, HttpMethod method, string host = VKCOM, string referer = "", string requestBody = "", bool withoutLogging = false) { if (withoutLogging) { Logger.LogMethod(); } else { Logger.LogMethod(url, method, host, referer, requestBody, withoutLogging); } HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url); httpWReq.Method = method.ToString(); httpWReq.ContentType = "application/x-www-form-urlencoded"; httpWReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; httpWReq.Host = host; httpWReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"; if (referer != "") { httpWReq.Referer = referer; } httpWReq.KeepAlive = true; httpWReq.AllowAutoRedirect = false; httpWReq.CookieContainer = HttpCookie; httpWReq.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3"); httpWReq.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7"); httpWReq.Headers.Add("DNT", "1"); Logger.AddText("Cookie=={0}", HttpCookie.CookieContainerToString()); if (method == HttpMethod.POST) { if (requestBody == "") { throw new System.ArgumentException("When method is POST, parameter cannot be null", "requestBody"); } byte[] data = Encoding.ASCII.GetBytes(requestBody); httpWReq.ContentLength = data.Length; using (Stream stream = httpWReq.GetRequestStream()) { stream.Write(data, 0, data.Length); } } HttpWebResponseEx responseEx = new HttpWebResponseEx(); try { responseEx.HttpWebResponse = (HttpWebResponse)httpWReq.GetResponse(); } catch (System.Net.WebException ex) { Logger.AddText(ex.StackTrace); responseEx.ResponseText = ex.Message; return(responseEx); } if (!withoutLogging) { Logger.AddText("Response={0}", responseEx.ToString()); } return(responseEx); }