Ejemplo n.º 1
0
        public List <string> Scrape(ScrapeCriteria scrapeCriteria)
        {
            List <string>   scrapedElements = new List <string>();
            MatchCollection matches         = Regex.Matches(scrapeCriteria.Data, scrapeCriteria.Regex, scrapeCriteria.RegexOption);

            foreach (Match match in matches)
            {
                if (!scrapeCriteria.Parts.Any())
                {
                    scrapedElements.Add(match.Groups[0].Value);
                }
                else
                {
                    foreach (var part in scrapeCriteria.Parts)
                    {
                        Match matchedPart = Regex.Match(match.Groups[0].Value, part.Regex, part.RegexOption);
                        if (matchedPart.Success)
                        {
                            scrapedElements.Add(matchedPart.Groups[1].Value);
                        }
                    }
                }
            }
            return(scrapedElements);
        }
        public ScrapeCriteria Build()
        {
            ScrapeCriteria scrapeCriteria = new ScrapeCriteria();

            scrapeCriteria.Data        = Data;
            scrapeCriteria.Regex       = Regex;
            scrapeCriteria.RegexOption = regexOptions;
            scrapeCriteria.Parts       = parts;
            return(scrapeCriteria);
        }