Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Fizzler.Systems.HtmlAgilityPack;
- using HtmlAgilityPack;
- namespace GetEm
- {
- class Data
- {
- public string Name;
- public int Count;
- public Data(string name, int count)
- {
- Name = name;
- Count = count;
- }
- public Data()
- {
- }
- public override string ToString()
- {
- return $"{Name} {Count}";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Data> inputData = new List<Data>();
- HtmlDocument doc = new HtmlDocument();
- doc.Load("Shinkai Project - general.html");
- var document = doc.DocumentNode;
- var chatlog=document.QuerySelectorAll(".chatlog__reaction");
- foreach (var htmlNode in chatlog)
- {
- try
- {
- string name=htmlNode.QuerySelector("img").GetAttributeValue("title","");
- int count = Convert.ToInt32(htmlNode.QuerySelector(".chatlog__reaction-count").InnerText);
- inputData.Add(new Data(name, count));
- }
- catch (Exception e)
- {
- //Console.WriteLine(e);
- }
- }
- var uniqueKeys = inputData.Select(n => n.Name).Distinct().ToList();
- List<Data> outputData = new List<Data>();
- foreach (var uniqueKey in uniqueKeys)
- {
- Data o = new Data();
- o.Name = uniqueKey;
- o.Count = inputData.Where(n => n.Name == uniqueKey).Sum(n => n.Count);
- outputData.Add(o);
- }
- File.WriteAllLines("output.txt",outputData.OrderByDescending(n => n.Count).Select(n=>n.ToString()).ToArray());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement