forked from TonyOcnos/romscraper-retrostic.com-WPF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUriContentFetcher.cs
47 lines (40 loc) · 1.79 KB
/
UriContentFetcher.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
using HtmlAgilityPack;
using System.Collections.Generic;
using System.Windows;
namespace RomScraper_DesktopApp
{
//Class to extract the different content (node or collection of nodes) we will use for the downloading service
public static class UriContentFetcher
{
#region RomSiteXPATHRetriever
public static Dictionary<string, string> RomSiteXPATHRetriever { get; set; } = new Dictionary<string, string>()
{
{ "PlatformsLinks", "//td[@class='d-block d-sm-none text-center']/a[contains(@href,'/roms/')]" },
{ "RomsLinks", "//td[@class='d-block d-sm-none text-center']/a[contains(@href,'/roms/')]" },
{ "FileName", "//td[contains(text(), '.zip') or contains(text(), '.bin')]" },
{ "Script", "//script[@type='text/javascript']" },
{ "SessionData", "//input[@type='hidden']" },
{ "Uri", "//a[@data-hook='review-title']" }
};
#endregion
//Dynamic function to select node or collection of nodes depending of the boolean parameter "mode".
public static dynamic GetContent(string uri, string xpath, bool mode)
{
var htmlDocument = new HtmlDocument();
try
{
HtmlWeb htmlweb = new HtmlWeb();
htmlDocument = htmlweb.Load(uri);
}
catch
{
MessageBox.Show("Connecting to site and retrieving data failed", "RomScraper - Fetching content...", MessageBoxButton.OK, MessageBoxImage.Information);
}
if (mode)
{
return htmlDocument.DocumentNode.SelectNodes(xpath);
}
return htmlDocument.DocumentNode.SelectSingleNode(xpath);
}
}
}