private List<NewsModel> StarNewsGroupNews(List<NewsModel> newsList) { string baseURL = "http://starnewsgroup.com"; string news = WebRequestData(baseURL + "/town.html?town=Manasquan"); HtmlDocument html = new HtmlDocument(); html.LoadHtml(HttpUtility.HtmlDecode(news)); HtmlNode listOfNewsEvents = html.DocumentNode.SelectNodes("//div[contains(@class,'content')]")[0].ChildNodes["ul"]; foreach (HtmlNode li in listOfNewsEvents.ChildNodes) { HtmlNode linkNode = li.ChildNodes["a"]; if (linkNode != null) { string href = linkNode.Attributes["href"].Value; string dateText = href.Substring(href.LastIndexOf(@"/") - 8, 8); string innerText = Regex.Replace(li.InnerText, @"^[^\r]*", ""); innerText = Regex.Replace(innerText, @"\t|\n|\r", ""); NewsModel newsArticle = new NewsModel(); newsArticle.Headline = innerText; newsArticle.Date = DateTime.ParseExact(dateText, "MM.dd.yy", System.Globalization.CultureInfo.InvariantCulture); newsArticle.Provider = "Star News Group"; newsArticle.URL = baseURL + href; newsList.Add(newsArticle); } } return newsList; }
private List<NewsModel> GetGoogleNews() { List<NewsModel> newsList = new List<NewsModel>(); string news = WebRequestData("https://news.google.com/news?q=manasquan&output=rss"); HtmlDocument html = new HtmlDocument(); html.LoadHtml(HttpUtility.HtmlDecode(news)); HtmlNode listOfNewsEvents = html.DocumentNode.ChildNodes["rss"].ChildNodes["channel"]; foreach (HtmlNode item in listOfNewsEvents.ChildNodes) { if (item.Name == "item") { string headline = string.Empty; DateTime date = new DateTime(); string provider = string.Empty; string url = string.Empty; foreach (HtmlNode attr in item.ChildNodes) { string attrText = attr.InnerText; if (attr.Name == "title") { string[] splits = attrText.Split('-'); for (int i = 0; i < splits.Length - 1; i++) { if (i == 0) headline = splits[i]; else headline = headline + "-" + splits[i]; } provider = splits[splits.Length - 1].Trim(); } else if (attr.Name == "pubdate") { date = DateTime.Parse(attrText); } else if (attr.Name == "link") { url = attr.NextSibling.InnerText; } } NewsModel newsArticle = new NewsModel(); newsArticle.Headline = headline; newsArticle.Date = date; newsArticle.Provider = provider; newsArticle.URL = url; newsList.Add(newsArticle); } } return newsList; }