示例#1
0
        private List <EmployeeDto> ParseEmployeePageContent(HtmlDocument htmlDoc, string urlBase)
        {
            var employees           = new List <EmployeeDto>();
            var employeeBioElements = htmlDoc.DocumentNode.SelectNodes($"//div[{XPathUtils.GetContainsClassExpression("employee-bio-item")}]");

            foreach (var employeeBioElement in employeeBioElements)
            {
                var employee = new EmployeeDto();

                var bioNameHeader = employeeBioElement.SelectSingleNode($"h2[{XPathUtils.GetContainsClassExpression("employee-bio-name")}]");
                if (bioNameHeader != null)
                {
                    employee.Name = bioNameHeader.FirstChild.InnerHtml;
                }

                var bioImageNormal = employeeBioElement.SelectSingleNode($"a/img[{XPathUtils.GetContainsClassExpression("employee-bio-default-image")}]");
                if (bioImageNormal != null)
                {
                    employee.NormalImageUrl = urlBase + bioImageNormal.GetAttributeValue("src", string.Empty);
                }

                var bioImageFun = employeeBioElement.SelectSingleNode($"a/img[{XPathUtils.GetContainsClassExpression("employee-bio-alternate-image")}]");
                if (bioImageFun != null)
                {
                    employee.FunImageUrl = urlBase + bioImageFun.GetAttributeValue("src", string.Empty);
                }

                employees.Add(employee);
            }
            return(employees);
        }