public static async Task <IEnumerable <object> > GetData() { var doc = new HtmlDocument(); doc.LoadHtml(await NetworkUtilities.LoadData(url, 65001)); var panes = doc.DocumentNode .Descendants("table") .First(x => x.Attributes.Contains("class") && x.Attributes["class"].Value.Contains("blog")) .Descendants("div") .Where(x => x.Attributes.Contains("class") && x.Attributes["class"].Value.Contains("contentpaneopen")); var data = panes.Select(pane => { var heading = pane.ChildNodes.First(child => child.Attributes.Contains("class") && child.Attributes["class"].Value.Contains("contentheading")); var content = pane.ChildNodes.First(child => child.Attributes.Contains("class") && child.Attributes["class"].Value.Contains("article-content")); return(new { Title = TextUtilities.ExtractText(heading), Content = TextUtilities.ExtractText(content) }); }); return(data); }
public static async Task <IEnumerable <Item> > GetData(int page, int category) { string url = string.Format(address, GetCategory(category), page); var doc = new HtmlDocument(); doc.LoadHtml(await NetworkUtilities.LoadData(url, 65001)); var findclasses = doc.DocumentNode .Descendants("div") .Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("f_news") ); List <Item> NList = new List <Item>(); foreach (var element in findclasses) { Item item = new Item { Title = element.ChildNodes[0].ChildNodes[1].InnerText, Picture = @"http://faragency.bg/" + element.ChildNodes[0].ChildNodes[0].Attributes["src"].Value, Date = element.ChildNodes[1].ChildNodes[0].InnerText.Replace(".", "/"), Description = element.ChildNodes[2].InnerText.Replace("/r/n", ""), Link = @"http://faragency.bg/" + element.ChildNodes[0].Attributes["href"].Value }; NList.Add(item); } return(NList); }
public static async Task <object> GetData() { var doc = new HtmlDocument(); doc.LoadHtml(await NetworkUtilities.LoadData(url, 1251)); var data = doc.DocumentNode.SelectNodes("//body/table/tr"); List <List <string> > tables = new List <List <string> >(); List <string> table = new List <string>(); foreach (var element in data) { if (element.Attributes.Count != 0) { string row = element.ChildNodes[3].InnerHtml; string[] rows; switch (table.Count) { case 1: row = row.Replace("<strong>", "").Replace("</strong>", ""); break; case 2: row = row.Replace("\r\n", " ").Replace(" ", " "); break; case 3: row = row.Replace(" ", ""); rows = row.Split("-"); table.Add(rows[0]); row = rows[1]; break; case 5: rows = row.Replace(" ", "").Replace("г.", "").Split(" до\r\n"); table.Add(rows[0]); row = rows[1]; break; } table.Add(row); } else { if (table.Count != 0) { tables.Add(table); } table = new List <string>(); } } return(tables); }
//Condition Info // -1 - Only Text // 0 - N/A // 1 - Very Good // 2 - Good // 3 - Average // 4 - Bad //Table Info //Долно Езерово - 0 //Меден Рудник - 1 //Бургас OPSIS - 2 //МОБИЛНА СТАНЦИЯ - 3 //Row Info // SO2 - 0 // NO2 - 1 // O3 - 2 // H2S - 3 // PM10 - 4 // Benzene - 5 // Styrene - 6 // Total - 7 public static async Task <object> GetData() { string url = string.Format(address, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour - 1); var doc = new HtmlDocument(); doc.LoadHtml(await NetworkUtilities.LoadData(url, 65001)); var findclasses = doc.DocumentNode .Descendants("div") .First(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("statsTable ") ); List <List <Cell> > table = new List <List <Cell> > { GetRow(findclasses.ChildNodes[1].ChildNodes[7]), GetRow(findclasses.ChildNodes[1].ChildNodes[11]), GetRow(findclasses.ChildNodes[1].ChildNodes[15]), GetRow(findclasses.ChildNodes[1].ChildNodes[19]) }; int totalCondition = 0; if (findclasses.ChildNodes[3].ChildNodes[3].Attributes["src"].Value.Contains("white")) { totalCondition = 0; } if (findclasses.ChildNodes[3].ChildNodes[3].Attributes["src"].Value.Contains("green")) { totalCondition = 1; } if (findclasses.ChildNodes[3].ChildNodes[3].Attributes["src"].Value.Contains("yellow")) { totalCondition = 2; } if (findclasses.ChildNodes[3].ChildNodes[3].Attributes["src"].Value.Contains("orange")) { totalCondition = 3; } if (findclasses.ChildNodes[3].ChildNodes[3].Attributes["src"].Value.Contains("red")) { totalCondition = 4; } return(new { table = table, totalCondition = totalCondition }); }
public static async Task <IEnumerable <string> > GetData() { var doc = new HtmlDocument(); doc.LoadHtml(await NetworkUtilities.LoadData(url, 65001)); var container = doc.DocumentNode .Descendants("div") .First(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("span9") ); return(container.ChildNodes .Select(node => node.InnerText) .Select(text => Regex .Replace(text, @"\s{2,}", " ") .Trim()) .Where(text => text.Length > 0) // Skip the title node (Район Бургас). .Skip(1) // And the useless ending comment. .SkipLast(1)); }