public HtmlDocument DownloadFile(string urlTemplate, bool isLegacy) { HtmlDocument htmlDocument; var nameFormat = (season.IsPlayoffs) ? "{1} - PLF - Pro Team Scoring {0}.html" : "{1} - Pro Team Scoring {0}.html"; var folderName = "SeasonFiles"; string seasonNumberText = (season.SeasonNumber < 10 ? "0" : "") + season.SeasonNumber.ToString(); string fileName = string.Format(nameFormat, seasonNumberText, season.LeagueAcronym); string directory = Path.Combine(Environment.CurrentDirectory, folderName); string filePath = Path.Combine(directory, fileName); Directory.CreateDirectory(directory); if (!File.Exists(filePath)) { var url = urlTemplate; url = url.Replace("{leagueLow}", season.LeagueAcronym.ToLowerInvariant()); url = url.Replace("{leagueUp}", season.LeagueAcronym.ToUpperInvariant()); url = url.Replace("{seasonNumber}", season.SeasonNumber.ToString()); url = url.Replace("{playoffAcro}", season.IsPlayoffs ? "PLF-" : ""); if (season.LeagueAcronym.ToLowerInvariant() == "shl") { url = url.Replace("{seasonType}", season.IsPlayoffs ? "Playoff" : "Season"); } if (season.LeagueAcronym.ToLowerInvariant() == "smjhl") { url = url.Replace("{seasonType}", season.IsPlayoffs ? "Playoffs" : "Season"); } if (season.LeagueAcronym.ToLowerInvariant() == "iihf") { url = url.Replace("{seasonType}", season.IsPlayoffs ? "medalround" : "roundrobin"); } htmlDocument = new HtmlWeb().Load(url); var title = htmlDocument.DocumentNode.Descendants("title").FirstOrDefault(); if (title == null || !title.InnerText.ToLowerInvariant().Contains("team scoring")) { throw new Exception("Page was not found online"); } htmlDocument.Save(filePath); } htmlDocument = new HtmlDocument(); htmlDocument.Load(filePath); return(htmlDocument); }
public HtmlDocument Load(string url) { var filename = UrlToFilename(url); var path = Path.Combine(Directory.GetCurrentDirectory(), filename); if (File.Exists(filename)) { var doc = new HtmlDocument(); doc.Load(path); return(doc); } var webDocument = new HtmlWeb().Load(url); webDocument.Save(path); return(webDocument); }
private void DownloadFile(string url, int seasonNumber, string leagueAcronym, bool isPlayoffs) { var nameFormat = (isPlayoffs) ? "{1} - PLF - Pro Team Scoring {0}.html" : "{1} - Pro Team Scoring {0}.html"; string seasonNumberText = (seasonNumber < 10 ? "0" : "") + seasonNumber.ToString(); string fileName = string.Format(nameFormat, seasonNumberText, leagueAcronym); string directory = Path.Combine(Environment.CurrentDirectory, @"SeasonFiles\"); string filePath = Path.Combine(directory, fileName); Directory.CreateDirectory(directory); //if (!File.Exists(filePath)) { _htmlDocument = new HtmlWeb().Load(url); _htmlDocument.Save(filePath); } _htmlDocument = new HtmlDocument(); _htmlDocument.Load(filePath); }