private async Task <BroadcastModelGroup> getSkySportsData(DateTime dateTime) { string result = await getData(SkySportsService.URL_SCHEDULE, dateTime); SkySportsService skySportsService = new SkySportsService(); return(skySportsService.MakeSkySportsData(result, dateTime)); }
public BroadcastModelGroup MakeSkySportsData(string strHTML, DateTime dateTime) { BroadcastModelGroup group = new BroadcastModelGroup(); group.Channel = SkySportsService.CHANNEL; group.ChannelShow = group.Channel; int startIdx = strHTML.IndexOf("<html", System.StringComparison.Ordinal); if (startIdx > 0) { strHTML = strHTML.Substring(startIdx); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(strHTML); List <DateTime> dateTimeSkySports = getDateTimeSkySports(doc); if (!getHasDate(dateTime, dateTimeSkySports)) { return(group); } SkySportsModel model; int nDayCurrent = (int)dateTime.DayOfWeek; //IEnumerable<HtmlNode> trNode = doc.DocumentNode.Descendants( "tr" ).Where(x => x.ParentNode.Name == "tbody"); foreach (HtmlNode element in doc.DocumentNode.Descendants("tr")) { if (element.ParentNode.Name != "tbody") { continue; } // 24 lines. int nSeq = 0; foreach (HtmlNode element2 in element.Descendants("td")) { if (element2.ParentNode != element) { continue; } ++nSeq; if (nSeq == 1) { continue; } int nDay = nSeq - 2; bool isYesterday = nDay == nDayCurrent - 1; if (!isYesterday && nDay != nDayCurrent) { continue; } if (element2.OuterHtml.IndexOf("NBA", StringComparison.Ordinal) == -1) { continue; } foreach (HtmlNode element3 in element2.Descendants("p")) { if (element3.OuterHtml.IndexOf("NBA", StringComparison.Ordinal) == -1) { continue; } model = new SkySportsModel(); string strTime = element2.Descendants("p").Where(x => x.GetAttributeValue("class", "") == "dateTxt mb10").First().InnerText; model.Time = strTime; model.Channel = SkySportsService.CHANNEL; model.Kind = BroadcastStruct.RERUN; model.Title = element2.Descendants("span").First().InnerText; model.DayPart = SkySportsService.getDayPartToDisplay(model.Time); if (!getIsAlreadyHas(group, model)) { group.Add(model); } } } } Debug.WriteLine(group.Count); return(group); }