public List <ISeason> GetSeasons(string episodeListUrl) { byte[] data = IOUtil.LoadUrl(episodeListUrl); string allEpisodesHtml = Encoding.ASCII.GetString(data); /* <div id="season-dropdown"> * <select onChange="javascript:document.location=this.value;"> * <option value="http://www.tv.com/americas-funniest-home-videos/show/3780/episode_listings.html?season=1">Season 1</option> * <option value="http://www.tv.com/americas-funniest-home-videos/show/3780/episode_listings.html?season=2">Season 2</option> */ Regex seasonsRegex = new Regex("<div id=\"season-dropdown\">(.*?)</div>", RegexOptions.Singleline); Match match = seasonsRegex.Match(allEpisodesHtml); List <ISeason> seasons = new List <ISeason>(); if (match.Success) { Regex seasonRegex = new Regex("<option value=\"([^\"]+)\"[^>]*>Season (.*?)</option>", RegexOptions.IgnoreCase | RegexOptions.Singleline); foreach (Match m in seasonRegex.Matches(match.Groups[1].Value)) { int seasonNum = int.Parse(m.Groups[2].Value); TvSeason season = new TvSeason(seasonNum, m.Groups[1].Value); seasons.Add(season); } if (seasons.Count == 0) { // more than likely there is only 1 season so they dont show the dropdown list... punks! TvSeason season = new TvSeason(1, episodeListUrl); seasons.Add(season); } } return(seasons); }
public List<ISeason> GetSeasons(string episodeListUrl) { byte[] data = IOUtil.LoadUrl(episodeListUrl); string allEpisodesHtml = Encoding.ASCII.GetString(data); /* <div id="season-dropdown"> <select onChange="javascript:document.location=this.value;"> <option value="http://www.tv.com/americas-funniest-home-videos/show/3780/episode_listings.html?season=1">Season 1</option> <option value="http://www.tv.com/americas-funniest-home-videos/show/3780/episode_listings.html?season=2">Season 2</option> */ Regex seasonsRegex = new Regex("<div id=\"season-dropdown\">(.*?)</div>", RegexOptions.Singleline); Match match = seasonsRegex.Match(allEpisodesHtml); List<ISeason> seasons = new List<ISeason>(); if (match.Success) { Regex seasonRegex = new Regex("<option value=\"([^\"]+)\"[^>]*>Season (.*?)</option>", RegexOptions.IgnoreCase | RegexOptions.Singleline); foreach (Match m in seasonRegex.Matches(match.Groups[1].Value)) { int seasonNum = int.Parse(m.Groups[2].Value); TvSeason season = new TvSeason(seasonNum, m.Groups[1].Value); seasons.Add(season); } if (seasons.Count == 0) { // more than likely there is only 1 season so they dont show the dropdown list... punks! TvSeason season = new TvSeason(1, episodeListUrl); seasons.Add(season); } } return seasons; }