public void ShowNames() { StringBuilder sb = new StringBuilder(); sb.Append("time"); foreach (string time in listTime) { string timestr = time.Insert(4, "-").Insert(7, "-").Insert(10, " ").Insert(13, ":").Substring(0, 16) + ":00"; sb.Append("," + timestr); //sb.Append("," + time.Substring(4, 8)); } sb.AppendLine(); StringBuilder sbCount = new StringBuilder(); foreach (string number in dicSubjects.Keys) { sbCount.Append("\"" + dicSubjects[number].Replace(",", "").ToCSVCell() + "\""); foreach (string time in listTime) { try { PetitionData data = dicData[number].dicTime[time]; sbCount.Append("," + data.count); } catch (KeyNotFoundException) { sbCount.Append(","); } } sbCount.AppendLine(); } File.WriteAllText("bluehouse.csv", sb.ToString() + sbCount.ToString(), new UTF8Encoding(true)); }
public void AddHtml(string path) { string time = Path.GetFileNameWithoutExtension(path); listTime.Add(time); string fn = Path.GetFileName(path); string html = File.ReadAllText(path); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); string xPath_li = "/html[1]/body[1]/div[2]/div[2]/section[2]/div[2]/div[1]/div[2]/div[2]/div[2]/div[2]/ul[1]/li[*]"; HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(xPath_li); Console.WriteLine("items : " + nodes.Count); foreach (var linode in nodes) { var nodea = linode.SelectSingleNode("./div[1]/div[3]/a[1]"); var nodecount = linode.SelectSingleNode(".//div[1]/div[6]"); string count = nodecount.InnerText.Replace(",", "").Replace("명", "").Trim(); string subject = nodea.InnerText; string line = time + "," + count + "," + subject; Console.WriteLine(line); string url = nodea.Attributes["href"].Value; PetitionData data = new PetitionData(); data.count = count; dicSubjects[url] = subject; if (!dicData.ContainsKey(url)) { dicData[url] = new PetitionDataHolder(); } dicData[url].dicTime[time] = data; } }