コード例 #1
0
        private static HtmlNode GatherInformation(FigureInformation figureInformation, HtmlNode currentNode, bool isGoingUp)
        {
            if (currentNode.Name.Equals("p"))
            {
                var classOfNode = currentNode.GetAttributeValue("class", string.Empty);

                if (classOfNode.Equals("exhibitnumber", StringComparison.CurrentCultureIgnoreCase))
                {
                    figureInformation.Number = currentNode.InnerText.Trim();
                }
                else if (classOfNode.Equals("exhibittitle", StringComparison.CurrentCultureIgnoreCase))
                {
                    figureInformation.Title = currentNode.InnerText.Trim();
                }
                else if (classOfNode.Contains("source"))
                {
                    figureInformation.Source = currentNode.InnerText.Trim();
                }
                else if (classOfNode.Contains("caption"))
                {
                    figureInformation.Title = currentNode.InnerText.Trim();
                }
            }
            else if (currentNode.Name.Equals("a"))
            {
                figureInformation.Link = currentNode.GetAttributeValue("href", null);
            }

            return(isGoingUp ? currentNode.PreviousSibling : currentNode.NextSibling);
        }
コード例 #2
0
        private static FigureInformation GetFigureInformation(HtmlNode node)
        {
            var figureInformation = new FigureInformation();

            var currentNode = node.ParentNode;

            for (int i = 0; i < MaximumNodeRange; i++)
            {
                if (figureInformation.IsFull || currentNode == null)
                {
                    break;
                }

                currentNode = GatherInformation(figureInformation, currentNode, true);
            }

            if (node.ParentNode != null)
            {
                currentNode = node.ParentNode.NextSibling;
                for (int i = 0; i < MaximumNodeRange; i++)
                {
                    if (figureInformation.IsFull || currentNode == null)
                    {
                        break;
                    }

                    currentNode = GatherInformation(figureInformation, currentNode, false);
                }
            }

            return(figureInformation);
        }