Пример #1
0
        static bool AssignDescriptionHelper(Bird bird, HtmlDocument document, int ul)
        {
            //Grap the h3 and assign as the Title of this SecondaryDescription. The h3 will always have an xpath [ul - 1]
            var headingNode = document.DocumentNode.SelectSingleNode($"/html/body/h3[{ul - 1}]");
            //This node contains all the bullet point descriptions
            var    descriptionNode = document.DocumentNode.SelectSingleNode($"/html/body/ul[{ul}]");
            string next            = string.Empty;

            if (descriptionNode != null)
            {
                string      title     = headingNode.InnerText.TrimEnd(' ', ':');
                Description secondary = new Description(bird, title);
                bird.Descriptions.Add(secondary);

                string        descriptionText  = descriptionNode.InnerHtml;
                List <string> tempDescriptions = descriptionText.Split('<').ToList();

                for (int i = 0; i < tempDescriptions.Count; i++)
                {
                    next = ScrubDescriptions(tempDescriptions[i]);
                    if (next != null)
                    {
                        BulletPoint bullet = new BulletPoint(next, secondary);
                        secondary.BulletPoints.Add(bullet);
                    }
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        //Import primaryIdTips from AssignLengths to avoid redundant work
        static void AssignDescriptions(Bird bird, HtmlDocument document, List <string> primaryIdTips)
        {
            //The descriptions in primaryIdTips are unqiue because we don't want the first two so I don't use AssignDescripionHelper()
            string      next    = string.Empty;
            Description primary = new Description(bird, "Primary");

            bird.Descriptions.Add(primary);
            for (int i = 2; i < primaryIdTips.Count; i++)
            {
                next = ScrubDescriptions(primaryIdTips[i]);
                if (next != null)
                {
                    BulletPoint bullet = new BulletPoint(next, primary);
                    primary.BulletPoints.Add(bullet);
                }
            }
            //Assign Secondary Descriptions
            int ul = 2;

            while (AssignDescriptionHelper(bird, document, ul))
            {
                ul++;
            }
            //Assign SimilarSpecies
            var h3Nodes = document.DocumentNode.SelectSingleNode("/html/body").Elements("h3");

            foreach (var h3 in h3Nodes)
            {
                if (h3.InnerText.Contains("Similar"))
                {
                    //Some pages are structured differently so we need to do this check
                    if (h3.NextSibling.NextSibling != null && h3.NextSibling.NextSibling.InnerText.Length > 5)
                    {
                        bird.SimilarSpecies = h3.NextSibling.NextSibling.InnerText.Replace(System.Environment.NewLine, string.Empty).TrimStart(' ');
                    }
                    else
                    {
                        bird.SimilarSpecies = h3.NextSibling.InnerText.Replace(System.Environment.NewLine, string.Empty).TrimStart(' ');
                    }
                }
            }
        }