Пример #1
0
        public List <string> Scrape(ScraperCriteria scraperCriteria)
        {
            List <string> scrappedElements = new List <string>();

            MatchCollection matches = Regex.Matches(scraperCriteria.Data, scraperCriteria.Regex, scraperCriteria.RegexOption);

            foreach (Match match in matches)
            {
                if (!scraperCriteria.Parts.Any())
                {
                    scrappedElements.Add(match.Groups[0].Value);
                }
                else
                {
                    foreach (var part in scraperCriteria.Parts)
                    {
                        Match matchedPart = Regex.Match(match.Groups[0].Value, part.Regex, part.RegexOption);

                        if (matchedPart.Success)
                        {
                            scrappedElements.Add(matchedPart.Groups[1].Value);
                        }
                    }
                }
            }



            return(scrappedElements);
        }
Пример #2
0
        public ScraperCriteria Build()
        {
            ScraperCriteria scraperCriteria = new ScraperCriteria();

            scraperCriteria.Data        = _data;
            scraperCriteria.Regex       = _regex;
            scraperCriteria.RegexOption = _regexOption;
            scraperCriteria.Parts       = _parts;
            return(scraperCriteria);
        }