-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scraper.cs
33 lines (30 loc) · 1.08 KB
/
Scraper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using WebScraper.Data;
namespace WebScraper.Workers
{
class Scraper
{
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;
}
}
}