-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComicHTML.csx
35 lines (28 loc) · 1.1 KB
/
ComicHTML.csx
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
#r "nuget: HtmlAgilityPack, 1.6.8"
using HtmlAgilityPack;
public struct ComicHTML
{
readonly HtmlDocument htmlDoc;
public ComicHTML(string html)
{
htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
}
public string GetComicPath() => htmlDoc.DocumentNode.Descendants("img")
.Select(e => e.GetAttributeValue("src", null))
.Single(s => !String.IsNullOrEmpty(s));
public DateTime GetComicDate()
{
var comicDate = htmlDoc.DocumentNode.Descendants("span")
.SingleOrDefault(e => e.GetAttributeValue("class", null) == "pub_date");
return DateTime.Parse(comicDate.InnerText);
}
public (string Path, bool Exists) GetNextComic() {
var nextComicLink = htmlDoc.DocumentNode.Descendants("link")
.SingleOrDefault(e => e.GetAttributeValue("rel", null) == "next");
if (nextComicLink == null) {
return ("", false);
}
return (nextComicLink.GetAttributeValue("href", null), true);
}
}