예제 #1
0
        public (string, string) GetGreetingAndMessage(LIUserData up, ScraperSettings _settings, string greeting, string message)
        {
            var tp = SplitUserName2(up.ProfileTitle);

            if (!string.IsNullOrWhiteSpace(greeting))
            {
                greeting = ReplaceTokens(_settings, greeting, tp.Item1, tp.Item2, up.CurrentJobTitle);
            }
            if (!string.IsNullOrWhiteSpace(message))
            {
                message = ReplaceTokens(_settings, message, tp.Item1, tp.Item2, up.CurrentJobTitle);
            }

            return(greeting, message);
        }
예제 #2
0
        private void ScrapeCurrentEmployeesResultPage(List <LIUserData> employees, IHtmlDocument document)
        {
            int empInNetwork = 0;

            Logger.Debug($"Scraping Employees Data...");

            Logger.Debug($"Querying page for required information");

            var titles       = document.QuerySelectorAll(LICompanyEmployeeSelectors.EmployeeNameCSSSelIdx);
            var profileUrls  = document.QuerySelectorAll(LICompanyEmployeeSelectors.EmployeeProfileUrlCSSSelIdx);
            var locations    = document.QuerySelectorAll(LICompanyEmployeeSelectors.EmployeeLocationCSSSelIdx);
            var designations = document.QuerySelectorAll(LICompanyEmployeeSelectors.EmployeeDesignationCSSSelIdx);
            //var designations2 = document.QuerySelectorAll(LICompanyEmployeeSelectors.EmployeeSRDesignationCSSSelIdx);
            var imageUrls   = document.QuerySelectorAll(LICompanyEmployeeSelectors.EmployeeImageUrlCSSSelIdx);
            var parentElems = document.QuerySelectorAll(LICompanyEmployeeSelectors.ParentElementCSSSel);


            Logger.Debug($"{parentElems.Length} Profiles found");

            LIUserData emp = null;
            int        currentPageEmployees = titles.Length;

            for (int i = 0; i < currentPageEmployees; i++)
            {
                try
                {
                    string title = GetNodeTextValue(titles[i]);

                    Logger.Debug($"Processing Profile {i + 1} , {title}");

                    if (title == "")
                    {
                        Logger.Debug("Blank titile found " + GetNodeTextValue(profileUrls[i], "href"));
                    }

                    if (!string.IsNullOrWhiteSpace(title) && !_util.ContainsInsensitive(title, _settings.IgnoreEmployeeTitle))
                    {
                        empInNetwork++;
                        emp = new LIUserData();

                        emp.ScraperProfileUrl = GetNodeTextValue(profileUrls[i], "href");
                        emp.ScraperProfileUrl = linkedInUrl + emp.ScraperProfileUrl;

                        emp.ProfileUrl = emp.ScraperProfileUrl;

                        emp.ProfileTitle    = title;
                        emp.Location        = GetNodeTextValue(locations[i]);
                        emp.CurrentJobTitle = GetNodeTextValue(designations[i]);

                        var pe = parentElems[i];
                        emp.ConnectionDegree = GetNodeTextValue(pe.QuerySelector(LICompanyEmployeeSelectors.EmployeeConnectionDegreeCSSSelIdx));

                        if (string.IsNullOrWhiteSpace(emp.ConnectionDegree))
                        {
                            emp.ConnectionDegree = "-";
                        }

                        emp.CurrentWorkingTitle = GetNodeTextValue(pe.QuerySelector(LICompanyEmployeeSelectors.EmployeeSRDesignationCSSSelIdx));

                        emp.Image = GetNodeTextValue(imageUrls[i], "src");
                        if (string.IsNullOrWhiteSpace(emp.Image) || emp.Image.Contains("data:image"))
                        {
                            //emp.ImageUrl = _settings.NoUserImageName;
                        }

                        emp.CurrentCompany = _util.GetCurrentCompanyName(emp.CurrentJobTitle, emp.CurrentWorkingTitle);

                        employees.Add(emp);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Error while scraping user profile card");
                }
            }


            Logger.Debug($"Employees in Network {empInNetwork}");
            Logger.Debug($"Employees not in Network {currentPageEmployees - empInNetwork}");
        }