コード例 #1
0
        public static IEnumerable <string> ElementSelectorAll(this IFetchedDocument document, string tag)
        {
            Guard.AgainstNull(nameof(document), document);
            Guard.AgainstNull(nameof(tag), tag);
            Guard.AgainstEmptyWhiteSpace(nameof(tag), tag);

            var getElement = new Regex($@"(?<=<{tag}>)(.|\n)*?(?=<\/{tag}>)",
                                       RegexOptions.Compiled | RegexOptions.Multiline);
            var matches  = getElement.Matches(document.Text());
            var contents = new List <string>();

            foreach (Match match in matches)
            {
                contents.Add(match.Value);
            }
            return(contents);
        }
コード例 #2
0
        public static string ElementSelector(this IFetchedDocument document, string tag)
        {
            Guard.AgainstNull(nameof(document), document);

            return(document.ElementSelectorAll(tag).SingleOrDefault() ?? string.Empty);
        }