-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecord.cs
48 lines (45 loc) · 1.51 KB
/
Record.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Text.RegularExpressions;
namespace Scraper
{
class Record
{
private readonly string urlFirst = "<a class=\"secondary-btn website-link\" href=\"";
private readonly string nameFirst = "<div class=\"sales-info\"><h1>";
private readonly string nameSecond = "<";
private readonly string mailFirst = "<a class=\"email-business\" href=\"mailto:";
private readonly Regex mailRegex = new Regex("<a class=\"email-business\" href=\"mailto:[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9._-]+\"");
private readonly string UnknownPlaceholder = "Unknown";
public Record(string data)
{
try
{
Name = data.Split(nameFirst)[1].Split(nameSecond)[0];
}
catch
{
Name = UnknownPlaceholder;
}
try
{
SiteUrl = data.Split(urlFirst)[1].Split('"')[0];
}
catch
{
SiteUrl = UnknownPlaceholder;
}
try
{
Email = mailRegex.IsMatch(data)
? mailRegex.Match(data).Value.Replace(mailFirst, string.Empty).Replace("\"", string.Empty)
: UnknownPlaceholder;
}
catch
{
Email = UnknownPlaceholder;
}
}
public string Name { get; set; }
public string SiteUrl { get; set; }
public string Email { get; set; }
}
}