コード例 #1
0
        private List <string> AppliesContentStrategy(IDocument document, StrategyContainer currentStrategy)
        {
            var             orderedStrategies = currentStrategy.ContentStrategy.OrderBy(x => x.Order).ToList();
            List <IElement> workCollection    = new List <IElement>();
            List <string>   result            = new List <string>();

            foreach (var strategy in orderedStrategies)
            {
                switch (strategy.Type)
                {
                case StrategyTypeEnum.None:
                    return(null);

                case StrategyTypeEnum.Xpath:
                    workCollection = ApplyXpath <IElement>(document, strategy.Value);
                    break;

                case StrategyTypeEnum.Apply:
                    result = ApplyTextSelector(workCollection, strategy.Value);
                    break;
                }
            }

            result.RemoveAll(string.IsNullOrWhiteSpace);
            return(result);
        }
コード例 #2
0
        private string AppliesTitleStrategy(IDocument document, StrategyContainer currentStrategy)
        {
            var             orderedStrategies = currentStrategy.TitleStrategy.OrderBy(x => x.Order).ToList();
            List <IElement> workCollection    = new List <IElement>();
            List <string>   result            = new List <string>();

            foreach (var strategy in orderedStrategies)
            {
                switch (strategy.Type)
                {
                case StrategyTypeEnum.None:
                    return(null);

                case StrategyTypeEnum.Xpath:
                    workCollection = ApplyXpath <IElement>(document, strategy.Value);
                    break;

                case StrategyTypeEnum.Apply:
                    result = ApplyTextSelector(workCollection, strategy.Value);
                    break;
                }
            }

            return(result.FirstOrDefault());
        }
コード例 #3
0
        private List <IHtmlAnchorElement> AppliesLinksStrategy(IDocument document, StrategyContainer currentStrategy)
        {
            var orderedStrategies = currentStrategy.LinksStrategy.OrderBy(x => x.Order).ToList();
            List <IHtmlAnchorElement> workCollection = new List <IHtmlAnchorElement>();

            foreach (var strategy in orderedStrategies)
            {
                switch (strategy.Type)
                {
                case StrategyTypeEnum.None:
                    return(null);

                case StrategyTypeEnum.Xpath:
                    workCollection = ApplyXpath <IHtmlAnchorElement>(document, strategy.Value);
                    break;

                case StrategyTypeEnum.Regex:
                    workCollection = ApplyRegexToLinksCollection(workCollection, strategy.Value);
                    break;
                }
            }

            return(workCollection);
        }