public string MyLoginForUnfollow(ref GlobDramProHttpHelper _GlobusHttpHelper, string url, string commentPostData, string referrer)
        {
            Log("[ " + DateTime.Now + " ] => [ Logging in with Account : " + Username + " ]");
            string Status = string.Empty;
            try
            {
                string firstUrl = "https://api.instagram.com/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29&redirect_uri=http://websta.me/&response_type=code&scope=comments+relationships+likes";

                //https://instagram.com/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29&redirect_uri=http://websta.me/&response_type=code&scope=comments+relationships+likes

                string secondURL = "https://instagram.com/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29&redirect_uri=http://websta.me/&response_type=code&scope=comments+relationships+likes";

                string res_secondURL = string.Empty;

                if (!string.IsNullOrEmpty(proxyAddress) && !string.IsNullOrEmpty(proxyPort))
                {
                    try
                    {
                        res_secondURL = _GlobusHttpHelper.getHtmlfromUrlProxy(new Uri(secondURL), proxyAddress, Convert.ToInt32(proxyPort), proxyUsername, proxyPassword);
                    }
                    catch (Exception ex)
                    {

                    }
                }
                else
                {

                    try
                    {
                        res_secondURL = _GlobusHttpHelper.getHtmlfromUrlProxy(new Uri(secondURL), "", 80, "", "");
                    }
                    catch { }
                }

                string nextUrl = "https://instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize/%3Fclient_id%3D9d836570317f4c18bca0db6d2ac38e29%26redirect_uri%3Dhttp%3A//websta.me/%26response_type%3Dcode%26scope%3Dcomments%2Brelationships%2Blikes";
                string res_nextUrl = _GlobusHttpHelper.getHtmlfromUrl(new Uri("http://websta.me/login"), "");

                //Get Token Number of Id
                int FirstPointToken_nextUrl = res_nextUrl.IndexOf("csrfmiddlewaretoken");
                string FirstTokenSubString_nextUrl = res_nextUrl.Substring(FirstPointToken_nextUrl);
                int SecondPointToken_nextUrl = FirstTokenSubString_nextUrl.IndexOf("/>");
                this.Token = FirstTokenSubString_nextUrl.Substring(0, SecondPointToken_nextUrl).Replace("csrfmiddlewaretoken", string.Empty).Replace("value=", string.Empty).Replace("\"", string.Empty).Replace("'", string.Empty).Trim();

                string login = "******";
                string postdata_Login = "******" + this.Token + "&username="******"&password="******"";

                string res_postdata_Login = _GlobusHttpHelper.postFormData(new Uri(login), postdata_Login, login, "");

                if (res_postdata_Login.Contains("Please enter a correct username and password"))
                {
                    //Status = "Failed";
                    this.LoggedIn = false;
                }
                else if (res_postdata_Login.Contains("requesting access to your Instagram account") || postdata_Login.Contains("is requesting to do the following"))
                {
                    //Status = "AccessIssue";
                }
                else if (res_postdata_Login.Contains("logout") || postdata_Login.Contains("LOG OUT"))
                {
                    //Status = "Success";
                    string zone = string.Empty;
                    if (res_postdata_Login.Contains("data('userid'") && res_postdata_Login.Contains(")"))
                    {
                        try
                        {
                            zone = ScrapUserName.getBetween(res_postdata_Login, "data('userid'", ")");
                            if (!string.IsNullOrEmpty(zone))
                            {
                                try
                                {
                                    int start = zone.IndexOf("'");
                                    int end = zone.LastIndexOf("'");
                                    Status = zone.Substring(start + 1, end - start - 1);
                                }
                                catch { }
                            }
                        }
                        catch { }
                    }
                    Log("[ " + DateTime.Now + " ] => [ Logged in with Account :" + Username + " ]");
                    this.LoggedIn = true;

                }

                //nameval.Clear();
                return Status;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
示例#2
0
        public void startUserScraper(string itemHash, int delay)
        {
            string pageSource = string.Empty;
            string response = string.Empty;
            string postData = string.Empty;
            List<string> lstCountScrapUser = new List<string>();

            if (stopScrapBool) return;
            try
            {
                GlobDramProHttpHelper _GlobusHttpHelper = new GlobDramProHttpHelper();
                pageSource = _GlobusHttpHelper.getHtmlfromUrl(new Uri(mainUrl),"");
                if (!string.IsNullOrEmpty(pageSource))
                {
                    //if (itemHash.StartsWith("#"))
                    //{
                    //    postData = "q=" + Uri.EscapeDataString(itemHash);
                    //}
                    //else
                    //{
                    //    postData = "q=" + Uri.EscapeDataString("#") + itemHash;
                    //}

                    postData = "q=" + Uri.EscapeDataString(itemHash);
                    string url = "http://websta.me/search/" + postData.Substring(postData.IndexOf("=") + 1);
                    string referer = "http://websta.me/";
                    response = _GlobusHttpHelper.postFormData(new Uri(url), postData, referer, "");

                    if (!string.IsNullOrEmpty(response))
                    {
                        if (response.Contains("class=\"username\""))
                        {
                            try
                            {
                                string[] arrOfUserName = Regex.Split(response, "class=\"username\"");

                                if (arrOfUserName.Length > 0)
                                {
                                    arrOfUserName = arrOfUserName.Skip(1).ToArray();
                                    foreach (string itemArray in arrOfUserName)
                                    {
                                        if (stopScrapBool) return;
                                        try
                                        {
                                            string startString = "href=\"/n/";
                                            string endString = "\">";
                                            if (itemArray.Contains(startString) && itemArray.Contains(endString))
                                            {
                                                string userName = string.Empty;
                                                try
                                                {
                                                    userName = getBetween(itemArray, startString, endString);
                                                    lstCountScrapUser.Add(userName);
                                                    lstCountScrapUser = lstCountScrapUser.Distinct().ToList();

                                                    if (!string.IsNullOrEmpty(userLink))
                                                    {
                                                        duplicateurl.Add(userLink + userName, userLink + userName);
                                                        #region CSV Write
                                                        try
                                                        {

                                                            string CSVData = itemHash.Replace(",", string.Empty) + "," + userName.Replace(",", string.Empty) + "," + (userLink + userName).Replace(",", string.Empty);
                                                            GramBoardProFileHelper.ExportDataCSVFile(CSVHeader, CSVData, CSVPath);
                                                        }
                                                        catch { }
                                                        try
                                                        {

                                                        GramBoardLogHelper.log.Info("["+ userName +","+ "itemHash:" +","+ itemHash +","+ "userName:"******","+ userName +","+ "userLink:" +","+ userLink + ","+" UserName" +userName +"]");

                                                        }
                                                        catch { };

                                                        #endregion

                                                        try
                                                        {
                                                            if (stopScrapBool) return;
                                                            lock (_lockObject)
                                                            {
                                                                try
                                                                {
                                                                    GramBoardLogHelper.log.Info("=> [  UserName" + userName + " ]");
                                                                    //HashLogger.printLogger("[ " + DateTime.Now + " ] => [ Delay for " + delay + " seconds ]");
                                                                    //GramBoardLogHelper.log.Info(" => [ Delay for " + delay + " seconds ]");
                                                                    //Thread.Sleep(delay * 1000);

                                                                    frm_stagram objfrm_stagram = (frm_stagram)Application.OpenForms["frm_stagram"];

                                                                    if (!string.IsNullOrEmpty(objfrm_stagram.txtDelayHashTag.Text) && NumberHelper.ValidateNumber(objfrm_stagram.txtDelayHashTag.Text))
                                                                    {
                                                                        mindelay = Convert.ToInt32(objfrm_stagram.txtDelayHashTag.Text);
                                                                    }
                                                                    if (!string.IsNullOrEmpty(objfrm_stagram.MinHashTagMinDelay.Text) && NumberHelper.ValidateNumber(objfrm_stagram.MinHashTagMinDelay.Text))
                                                                    {
                                                                        maxdelay = Convert.ToInt32(objfrm_stagram.MinHashTagMinDelay.Text);
                                                                    }

                                                                    Random obj_rn = new Random();
                                                                    int delay1 = RandomNumberGenerator.GenerateRandom(mindelay, maxdelay);
                                                                    delay1 = obj_rn.Next(mindelay, maxdelay);
                                                                    GramBoardLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Delay For " + delay1 + " Seconds ]");
                                                                    Thread.Sleep(delay1 * 1000);
                                                                }
                                                                catch { }
                                                            }
                                                            if (lstCountScrapUser.Count >= ClGlobul.countNOOfFollowersandImageDownload)
                                                            {
                                                                return;
                                                            }
                                                        }
                                                        catch { }
                                                    }
                                                }
                                                catch { }
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                            catch { }
                        }
                    }//End of if (!string.IsNullOrEmpty(response))
                    else
                    {
                        //Do Nothing yet
                    }

                }//End of if (!string.IsNullOrEmpty(pageSource))
            }
            catch { }
            //GlobusLogHelper.log.Info("[" + DateTime.Now + " ]=>[Process Completed]");
            //HashLogger.printLogger("[ " + DateTime.Now + " ] => [  Process Completed ]");
        }
        public string postFormDataForFollowUserNew(Uri url, string postData, string Referes, NameValueCollection nameValueCollection,string user,string pass)
        {
            GlobDramProHttpHelper _GlobusHttpHelper = new GlobDramProHttpHelper();

            string Username = user;
            string Password = pass;

            string firstUrl = "https://api.instagram.com/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29&redirect_uri=http://websta.me/&response_type=code&scope=comments+relationships+likes";

            //https://instagram.com/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29&redirect_uri=http://websta.me/&response_type=code&scope=comments+relationships+likes

            string secondURL = "https://instagram.com/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29&redirect_uri=http://websta.me/&response_type=code&scope=comments+relationships+likes";
            string res_secondURL = _GlobusHttpHelper.getHtmlfromUrlProxy(new Uri(secondURL), proxyAddress, 80, proxyUsername, proxyPassword);

            string nextUrl = "https://instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize/%3Fclient_id%3D9d836570317f4c18bca0db6d2ac38e29%26redirect_uri%3Dhttp%3A//websta.me/%26response_type%3Dcode%26scope%3Dcomments%2Brelationships%2Blikes";
            string res_nextUrl = _GlobusHttpHelper.getHtmlfromUrlProxy(new Uri(nextUrl), proxyAddress, 80, proxyUsername, proxyPassword);

            #region << Get Token >>
            //Get Token Number of Id
            int FirstPointToken_nextUrl = res_nextUrl.IndexOf("csrfmiddlewaretoken");
            string FirstTokenSubString_nextUrl = res_nextUrl.Substring(FirstPointToken_nextUrl);
            int SecondPointToken_nextUrl = FirstTokenSubString_nextUrl.IndexOf("/>");
            string Token = FirstTokenSubString_nextUrl.Substring(0, SecondPointToken_nextUrl).Replace("csrfmiddlewaretoken", string.Empty).Replace("value=", string.Empty).Replace("\"", string.Empty).Replace("'", string.Empty).Trim();
            #endregion

            string login = "******";
            string postdata_Login = "******" + Token + "&username="******"&password="******"";

            string res_postdata_Login = _GlobusHttpHelper.postFormData(new Uri(login), postdata_Login, login, "");
            gRequest = (HttpWebRequest)WebRequest.Create(url);

            //gRequest.ServicePoint.Expect100Continue = false;

            gRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36";
            gRequest.Accept = "application/json, text/javascript, */*; q=0.01";

            gRequest.CookieContainer = new CookieContainer();// gCookiesContainer;
            gRequest.Method = "POST";
            gRequest.KeepAlive = true;
            gRequest.ContentType = @"application/x-www-form-urlencoded; charset=UTF-8";
            gRequest.Headers["Accept-Language"] = "en-us,en;q=0.5";
            gRequest.Headers["X-Requested-With"] = "XMLHttpRequest";

            gRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

            if (!string.IsNullOrEmpty(Referes))
            {
                gRequest.Referer = Referes;
            }

            try
            {
                if (nameValueCollection != null)
                {
                    foreach (string item in nameValueCollection.Keys)
                    {
                        gRequest.Headers.Add(item, nameValueCollection[item]);
                    }
                }
            }
            catch (Exception)
            {
            }

            ///Modified BySumit 18-11-2011
            ChangeProxy(proxyAddress, port, proxyUsername, proxyPassword);

            #region CookieManagement
            if (this.gCookies != null && this.gCookies.Count > 0)
            {
                setExpect100Continue();
                gRequest.CookieContainer.Add(gCookies);
            }

            //logic to postdata to the form
            try
            {
                setExpect100Continue();
                string postdata = string.Format(postData);
                byte[] postBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(postData);
                gRequest.ContentLength = postBuffer.Length;
                Stream postDataStream = gRequest.GetRequestStream();
                postDataStream.Write(postBuffer, 0, postBuffer.Length);
                postDataStream.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                // //Logger.LogText("Internet Connectivity Exception : "+ ex.Message,null);
            }
            //post data logic ends

            //Get Response for this request url

            string html;

            try
            {
                gResponse = (HttpWebResponse)gRequest.GetResponse();
            }
            catch (WebException ex)
            {
                Console.WriteLine(ex.Message);
                // //Logger.LogText("Response from " + url + ":" + ex.Message, null);
            }

            //check if the status code is http 200 or http ok

            if (gResponse.StatusCode == HttpStatusCode.OK)
            {
                //get all the cookies from the current request and add them to the response object cookies
                setExpect100Continue();
                gResponse.Cookies = gRequest.CookieContainer.GetCookies(gRequest.RequestUri);
                //check if response object has any cookies or not
                //Added by sandeep pathak
                //gCookiesContainer = gRequest.CookieContainer;

                if (gResponse.Cookies.Count > 0)
                {
                    //check if this is the first request/response, if this is the response of first request gCookies
                    //will be null
                    if (this.gCookies == null)
                    {
                        gCookies = gResponse.Cookies;
                    }
                    else
                    {
                        foreach (Cookie oRespCookie in gResponse.Cookies)
                        {
                            bool bMatch = false;
                            foreach (Cookie oReqCookie in this.gCookies)
                            {
                                if (oReqCookie.Name == oRespCookie.Name)
                                {
                                    oReqCookie.Value = oRespCookie.Value;
                                    bMatch = true;
                                    break; //
                                }
                            }
                            if (!bMatch)
                                this.gCookies.Add(oRespCookie);
                        }
                    }
                }
            #endregion

                StreamReader reader = new StreamReader(gResponse.GetResponseStream());
                string responseString = reader.ReadToEnd();
                reader.Close();
                //Console.Write("Response String:" + responseString);
                return responseString;
            }
            else
            {
                return "Error in posting data";
            }
        }