public NaverGameModelDailyList MakeNaverData(string strXML) { NaverGameModelDailyList dailyList = new NaverGameModelDailyList(); int startIdx = strXML.IndexOf("<html", System.StringComparison.Ordinal); if (startIdx > 0) { strXML = strXML.Substring(startIdx); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(strXML); System.IO.StringWriter sw = new System.IO.StringWriter(); XmlWriter xw = XmlWriter.Create(sw); doc.Save(xw); string result = sw.ToString(); XDocument xd = XDocument.Parse(result); NaverGameModel model; foreach (XElement element in xd.Descendants("li")) { if (!element.Parent.HasAttributes) { continue; } if (element.Parent.Attribute("class") == null) { continue; } string strParentValue = element.Parent.Attribute("class").Value; if (strParentValue.IndexOf("sch_lst", StringComparison.Ordinal) == -1) { continue; } model = new NaverGameModel(); foreach (XElement element2 in element.Descendants("a")) { ///basketball/gamecenter/nba/index.nhn?tab=record&gameId=2017022319 model.Link = element2.Attribute("href").Value; model.Values = StringUtil.Trim(element2.Value); dailyList.Add(model); } } return(dailyList); }
/// <summary> /// if there is no same game data, return "". /// </summary> /// <returns>The link by game title.</returns> /// <param name="dailyGameList">Daily game list.</param> /// <param name="gameTitle">Game title.</param> private string FindLinkByGameTitle(NaverGameModelDailyList dailyGameList, string gameTitle) { NaverGameModel model; for (int i = 0; i < dailyGameList.Count; ++i) { model = dailyGameList[i]; if (getIsSameGame(model, gameTitle)) { return(model.Link); } } return(""); }
public async Task <string> GetGameURL(DateTime dateTime, string gameTitle) { if (list == null) { list = new List <NaverGameModelDailyList>(); } NaverGameModelDailyList dailyGameList = GetDailyGameListByDate(dateTime); if (dailyGameList == null) { dailyGameList = await GetHttpDailyGameList(dateTime); dailyGameList.Month = dateTime.Month; dailyGameList.Day = dateTime.Day; list.Add(dailyGameList); } return(URL + FindLinkByGameTitle(dailyGameList, gameTitle)); }