コード例 #1
0
        public void StartCampaignInBoardProGetDataWithPagination(ref GlobusHttpHelper HttpHelper, string Account, string FirstName, string LastName, string Location, string Country, string LocationArea, string PostalCode, string Company, string Keyword, string Title, string IndustryType, string Relationship, string language, string Groups, string FileName, string TitleValue, string CompanyValue, string within, string YearsOfExperience, string Function, string SeniorLevel, string IntrestedIn, string CompanySize, string Fortune1000, string RecentlyJoined)
        {
            string ResponseWallPostForPremiumAcc = string.Empty;
            string NewSearchPage = string.Empty;
            string PostResponce = string.Empty;
            string PostRequestURL = string.Empty;
            string PostdataForPagination = string.Empty;
            string csrfToken = string.Empty;
            Queue<string> queRecordUrl = new Queue<string>();
            List<string> RecordURL = new List<string>();

            #region Login
            try
            {
                //Temprary class
                //======================================================
                //string tempurl = "http://www.linkedin.com/profile/view?id=224916256&authType=OUT_OF_NETWORK&authToken=SWNz&locale=en_US&srchid=3387141351401255871148&srchindex=1&srchtotal=2017&trk=vsrp_people_res_name&trkInfo=VSRPsearchId%3A3387141351401255871148%2CVSRPtargetId%3A224916256%2CVSRPcmpt%3Aprimary";
                //CrawlingLinkedInPage(tempurl, ref HttpHelper);
                //======================================================

                if (SearchCriteria.starter)
                {
                    #region Serch

                    string pageSourceaAdvanceSearch = HttpHelper.getHtmlfromUrl1(new Uri("http://www.linkedin.com/search"));
                    NewSearchPage = string.Empty;

                    if (pageSourceaAdvanceSearch.Contains("csrfToken"))
                    {
                        try
                        {
                            int startindex = pageSourceaAdvanceSearch.IndexOf("csrfToken");
                            if (startindex > 0)
                            {
                                string start = pageSourceaAdvanceSearch.Substring(startindex);
                                int endindex = start.IndexOf(">");
                                string end = start.Substring(0, endindex);
                                csrfToken = end.Replace("csrfToken=", "").Replace("\\", "").Replace("\"", string.Empty); ;
                            }
                        }
                        catch { }

                    }

                    try
                    {
                        if (Location == "Y")
                        {
                            Country = string.Empty;
                        }

                        //if (NewSearchPage == string.Empty)
                        //{
                        //    string PostDataForPrimiumAccount = "csrfToken=" + csrfToken + "&keepFacets=true&pplSearchOrigin=ADVS&keywords=" + Uri.EscapeDataString(SearchCriteria.Keyword) + "&fname=" + SearchCriteria.FirstName + "&lname=" + SearchCriteria.LastName + "&companyScope=" + SearchCriteria.CompanyValue + "&searchLocationType=" + SearchCriteria.Location + "&countryCode=" + SearchCriteria.Country + "&postalCode=" + SearchCriteria.PostalCode + "&distance=" + SearchCriteria.within + "&title=&company=" + SearchCriteria.Company + "&currentCompany=" + SearchCriteria.CompanyValue + "&school=&I=" + SearchCriteria.IndustryType + "&FG=" + SearchCriteria.Group + "&N=" + SearchCriteria.Relationship + "&L=" + SearchCriteria.language + "&FA=" + SearchCriteria.Function + "&CS=" + SearchCriteria.CompanySize + "&SE=" + SearchCriteria.SeniorLevel + "&P=" + SearchCriteria.InerestedIn + "&TE=" + SearchCriteria.YearOfExperience + "&DR=" + SearchCriteria.RecentlyJoined + "&F=" + SearchCriteria.Fortune1000 + "&sortCriteria=R&viewCriteria=2&%2Fsearch%2Ffpsearch=Search";
                        //    ResponseWallPostForPremiumAcc = HttpHelper.postFormData(new Uri("http://www.linkedin.com/search/fpsearch"), PostDataForPrimiumAccount);
                        //}
                        //else
                        {
                            string GetDataForPrimiumAccount = string.Empty;
                            GetDataForPrimiumAccount = "http://www.linkedin.com/vsearch/p?openAdvancedForm=true&keywords=" + Uri.EscapeDataString(Keyword) + "&title=" + Title + "&titleScope=" + TitleValue + "&firstName=" + FirstName + "&lastName=" + LastName + "&postalCode=" + PostalCode + "&companyScope=" + CompanyValue + "&locationType=" + Location + "&countryCode=" + Country + "&company=" + Company + "&distance=" + within + "&f_FG=" + Groups + "&f_L=" + language + "&f_N=" + Relationship + "&f_G=" + LocationArea + "&f_I=" + IndustryType + "&f_TE=" + YearsOfExperience + "&f_FA=" + Function + "&f_SE=" + SeniorLevel + "&f_P=" + IntrestedIn + "&f_CS=" + CompanySize + "&f_F=" + Fortune1000 + "&f_DR=" + RecentlyJoined + "&orig=ADVS";
                            ResponseWallPostForPremiumAcc = HttpHelper.getHtmlfromUrl1(new Uri(GetDataForPrimiumAccount));

                        }

                    }
                    catch { }

                    string facetsOrder = string.Empty;
                    if (PostResponce.Contains("facetsOrder"))
                    {
                        facetsOrder = ResponseWallPostForPremiumAcc.Substring(PostResponce.IndexOf("facetsOrder"), 200);
                        string[] Arr3 = facetsOrder.Split('"');
                        facetsOrder = Arr3[2];
                        string DecodedCharTest = Uri.UnescapeDataString(facetsOrder);
                        string DecodedEmail = Uri.EscapeDataString(facetsOrder);
                        facetsOrder = DecodedEmail;
                    }
                    #endregion
                }
                int pagenumber = 0;
                string strPageNumber = string.Empty;
                string[] Arr12 = Regex.Split(ResponseWallPostForPremiumAcc, "<li");
                foreach (string item in Arr12)
                {
                    if (SearchCriteria.starter)
                    {
                        #region Loop
                        if (!item.Contains("<!DOCTYPE"))
                        {
                            if (item.Contains("results-summary"))
                            {
                                string data = RemoveAllHtmlTag.StripHTML(item);
                                data = data.Replace("\n", "");
                                if (data.Contains(">"))
                                {
                                    string[] ArrTemp = data.Split('>');
                                    data = ArrTemp[1];
                                    data = data.Replace("results", "");
                                    data = data.Trim();
                                    string[] ArrTemp1 = data.Split(' ');
                                    data = ArrTemp1[0].Replace(',', ' ').Trim();
                                    strPageNumber = data.Replace(" ", string.Empty);
                                    break;
                                }

                            }
                        }
                        #endregion
                    }
                }

                if (string.IsNullOrEmpty(strPageNumber))
                {
                    try
                    {
                        if (ResponseWallPostForPremiumAcc.Contains("resultCount"))
                        {
                            string[] countResultArr = Regex.Split(ResponseWallPostForPremiumAcc, "resultCount");

                            if (countResultArr.Length > 1)
                            {
                                string tempResult = countResultArr[1].Substring(0, countResultArr[1].IndexOf(","));

                                if (tempResult.Contains("<strong>"))
                                {
                                    strPageNumber = tempResult.Substring(tempResult.IndexOf("<strong>"), tempResult.IndexOf("</strong>", tempResult.IndexOf("<strong>")) - tempResult.IndexOf("<strong>")).Replace("<strong>", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Trim();
                                }
                                else if (tempResult.Contains(":"))
                                {
                                    strPageNumber = tempResult.Replace(":", string.Empty).Replace("\"", string.Empty);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {

                    }
                }

                if (string.IsNullOrEmpty(strPageNumber))
                {
                    try
                    {
                        if (ResponseWallPostForPremiumAcc.Contains("results_count_without_keywords_i18n"))
                        {
                            string[] countResultArr = Regex.Split(ResponseWallPostForPremiumAcc, "results_count_without_keywords_i18n");

                            if (countResultArr.Length > 1)
                            {
                                string tempResult = countResultArr[1].Substring(0, countResultArr[1].IndexOf(","));

                                if (tempResult.Contains("<strong>"))
                                {
                                    strPageNumber = tempResult.Substring(tempResult.IndexOf("<strong>"), tempResult.IndexOf("</strong>", tempResult.IndexOf("<strong>")) - tempResult.IndexOf("<strong>")).Replace("<strong>", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Trim();
                                }
                                else if (tempResult.Contains(":"))
                                {
                                    strPageNumber = tempResult.Replace(":", string.Empty).Replace("\"", string.Empty);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {

                    }
                }

                string logtag = string.Empty;

                try
                {
                    pagenumber = int.Parse(strPageNumber);

                    AddToLogger("[ " + DateTime.Now + " ] => [ Total Results :  " + pagenumber + " ]");
                }
                catch (Exception)
                {

                }

                pagenumber = (pagenumber / 10) + 1;

                if (pagenumber == -1)
                {
                    pagenumber = 2;
                }

                if (pagenumber == 1)
                {
                    pagenumber = 2;
                }

                string GetResponce = string.Empty;
                string GetRequestURL = string.Empty;

                if (pagenumber >= 1)
                {
                    _HttpHelper = HttpHelper;

                    //new Thread(() =>
                   // {
                        if (SearchCriteria.starter)
                        {
                            //string CheckString = "CampaignScraper" + FileName;
                            //finalUrlCollection(RecordURL);

                        }

                   // }).Start();

                    for (int i = 1; i <= pagenumber; i++)
                    {
                        if (SearchCriteria.starter)
                        {
                            #region loop

                            if (ResponseWallPostForPremiumAcc.Contains("Account Type:</span> Basic"))
                            {
                                try
                                {
                                    PostRequestURL = "http://www.linkedin.com/search/hits";
                                    PostdataForPagination = "keywords=" + Uri.EscapeDataString(Keyword) + "&title=" + Uri.EscapeDataString(Title) + "&fname=" + FirstName + "&lname=" + LastName + "&searchLocationType=" + Location + "&f_FG=" + Groups + "&companyScope=" + CompanyValue + "&countryCode=" + Country + "&company=" + Company + "&viewCriteria=1&sortCriteria=R&facetsOrder=CC%2CN%2CG%2CI%2CPC%2CED%2CL%2CFG%2CTE%2CFA%2CSE%2CP%2CCS%2CF%2CDR&page_num=" + i + "&openFacets=N%2CCC%2CG";
                                    PostResponce = HttpHelper.postFormData(new Uri(PostRequestURL), PostdataForPagination);
                                    //Temporosy code for client
                                    //GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Pagesource 3 >>>> " + PostResponce, Globals.Path_InBoardProGetDataPagesource);

                                }
                                catch { }
                            }
                            else if (ResponseWallPostForPremiumAcc.Contains("Account Type:</span> Executive"))
                            {
                                try
                                {
                                    PostRequestURL = "http://www.linkedin.com/search/hits";
                                    PostdataForPagination = "keywords=" + Uri.EscapeDataString(Keyword) + "&title=" + Uri.EscapeDataString(Title) + "&fname=" + FirstName + "&lname=" + LastName + "&searchLocationType=" + Location + "&f_FG=" + Groups + "&companyScope=" + CompanyValue + "&countryCode=" + Country + "&keepFacets=keepFacets&I=" + IndustryType + "&SE=" + SeniorLevel + "&pplSearchOrigin=ADVS&viewCriteria=2&sortCriteria=R&facetsOrder=N%2CCC%2CI%2CPC%2CED%2CL%2CFG%2CTE%2CFA%2CSE%2CP%2CCS%2CF%2CDR%2CG&page_num=" + i + "&openFacets=N%2CCC%2CI";

                                    PostResponce = HttpHelper.postFormData(new Uri(PostRequestURL), PostdataForPagination);
                                    //Temporosy code for client
                                    //GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Pagesource 3 >>>> " + PostResponce, Globals.Path_InBoardProGetDataPagesource);
                                }
                                catch { }
                            }
                            else if (ResponseWallPostForPremiumAcc.Contains("openAdvancedForm=true"))
                            {
                                PostRequestURL = "http://www.linkedin.com/vsearch/p?";
                                PostdataForPagination = "keywords=" + Uri.EscapeDataString(Keyword) + "&title=" + Uri.EscapeDataString(Title) + "&titleScope=" + TitleValue + "&firstName=" + FirstName + "&lastName=" + LastName + "&postalCode=" + PostalCode + "&openAdvancedForm=true&companyScope=" + CompanyValue + "&locationType=" + Location + "&f_FG=" + Groups + "&countryCode=" + Country + "&company=" + Company + "&distance=" + within + "&f_N=" + Relationship + "&f_G=" + LocationArea + "&f_I=" + IndustryType + "&f_TE=" + YearsOfExperience + "&f_FA=" + Function + "&f_SE=" + SeniorLevel + "&f_P=" + IntrestedIn + "&f_CS=" + CompanySize + "&f_F=" + Fortune1000 + "&f_DR=" + RecentlyJoined + "&orig=ADVS&page_num=" + i + "";
                                PostResponce = HttpHelper.postFormData(new Uri(PostRequestURL), PostdataForPagination);
                                //Temporosy code for client
                                GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Pagesource 4 >>>> " + PostResponce, Globals.Path_InBoardProGetDataPagesource);
                            }
                            else
                            {
                                try
                                {
                                    PostRequestURL = "http://www.linkedin.com/search/hits";
                                    PostdataForPagination = "keywords=" + Uri.EscapeDataString(SearchCriteria.Keyword) + "&title=" + Uri.EscapeDataString(Title) + "&fname=" + FirstName + "&lname=" + LastName + "&searchLocationType=" + Location + "&f_FG=" + Groups + "&countryCode=" + Country + "&viewCriteria=1&sortCriteria=R&facetsOrder=CC%2CN%2CG%2CI%2CPC%2CED%2CL%2CFG%2CTE%2CFA%2CSE%2CP%2CCS%2CF%2CDR&page_num=" + i + "&openFacets=N%2CCC%2CG";
                                    PostResponce = HttpHelper.postFormData(new Uri(PostRequestURL), PostdataForPagination);
                                }
                                catch { }
                            }
                            clsDBQueryManager QM = new clsDBQueryManager();
                            if (PostResponce.Contains("/profile/view?id"))
                            {

                                List<string> PageSerchUrl = GettingAllUrl(PostResponce);
                                PageSerchUrl.Distinct();

                                if (PageSerchUrl.Count == 0)
                                {
                                    AddToLogger("[ " + DateTime.Now + " ] => [ On the basis of your Account you can able to see " + RecordURL.Count + " Results ]");
                                    break;
                                }

                                foreach (string item in PageSerchUrl)
                                {
                                    if (SearchCriteria.starter)
                                    {
                                        if (item.Contains("pp_profile_photo_link") || item.Contains("vsrp_people_res_name") || item.Contains("profile/view?"))
                                        {
                                            try
                                            {
                                                string urlSerch = item;
                                                if (urlSerch.Contains("vsrp_people_res_name"))
                                                {
                                                    RecordURL.Add(urlSerch);
                                                    try
                                                    {
                                                        string query = "Insert Into tb_CampaignScraperURL (Url, Account, Status) Values ('" + urlSerch + "','" + Account + "','" + "Not Scraped');";
                                                        QM.InsertUrl(query);
                                                    }
                                                    catch
                                                    { }

                                                    RecordURL = RecordURL.Distinct().ToList();
                                                }

                                                try
                                                {
                                                    AddToLogger("[ " + DateTime.Now + " ] => [ " + urlSerch + " ]");
                                                }
                                                catch { }
                                            }
                                            catch { }
                                        }
                                    }
                                }
                            }

                            else if (!PostResponce.Contains("pp_profile_name_link") && PostResponce.Contains("Custom views are no longer supported. Please select either Basic or Expanded view"))
                            {
                                break;
                            }

                            #endregion
                        }
                    }
                    finalUrlCollection(RecordURL, ref HttpHelper, FileName);

                }
                #region For Else
                else
                {
                    if (SearchCriteria.starter)
                    {

                        #region loop
                        if (ResponseWallPostForPremiumAcc.Contains("/profile/view?id"))
                        {

                            List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls(ResponseWallPostForPremiumAcc, "profile/view?id");
                            if (PageSerchUrl.Count == 0)
                            {

                                AddToLogger("[ " + DateTime.Now + " ] => [ On the basis of your Account or Your Input you can able to see " + RecordURL.Count + "  Results ]");

                            }

                            foreach (string item in PageSerchUrl)
                            {
                                if (SearchCriteria.starter)
                                {
                                    if (item.Contains("pp_profile_name_link"))
                                    {
                                        string urlSerch = "http://www.linkedin.com" + item;
                                        AddToLogger("[ " + DateTime.Now + " ] => [ " + urlSerch + " ]");
                                        RecordURL.Add(urlSerch);
                                        queRecordUrl.Enqueue(urlSerch);

                                    }
                                }
                            }
                        }
                        #endregion
                    }

                }

                //if (strPageNumber != string.Empty)
                //{
                //    if (strPageNumber != "0")
                //    {
                //        AddToLogger("-------------------------------------------------------------------------------------------------------------------------------");
                //        AddToLogger("[ " + DateTime.Now + " ] => [ No Of Results Found >>> " + strPageNumber + " ]");
                //    }
                //}

                RecordURL.Distinct();

            }

                #endregion

            catch { }
            #endregion
        }