예제 #1
0
        private async void Form1_Load(object sender, EventArgs e)
        {
            this.IsMdiContainer = true;
            var width  = tabControl1.Width / tabControl1.TabPages.Count;
            var height = tabControl1.ItemSize.Height;

            tabControl1.ItemSize = new Size(width, height);

            StartLoading();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            LoadIconAsync();
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
            championInfos = await Task.Run(() => Crawler.GetPostionChampions());

            InitTabPage();
            StopLoading();
        }
예제 #2
0
        public static ChampionInfos GetPostionChampions()
        {
            string         page    = "http://www.op.gg/champion/statistics/";
            HttpWebRequest request = WebRequest.CreateHttp(page);

            request.Headers = headers;
            var stream = request.GetResponse().GetResponseStream();

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.Load(stream, Encoding.UTF8);
            ChampionInfos championInfos = new ChampionInfos();
            var           properties    = championInfos.GetType().GetProperties();

            foreach (var property in properties)
            {
                string position = property.Name;
                var    nodes    = doc.DocumentNode.SelectNodes($"//tbody[@class=\"tabItem champion-trend-tier-{position.ToUpper()}\"]/tr");


                List <Champion> champions = new List <Champion>();
                foreach (var node in nodes)
                {
                    var      index    = node.SelectSingleNode(".//i").GetAttributeValue("class", string.Empty).Split('-').Last();
                    var      name     = node.SelectSingleNode(".//div[@class=\"champion-index-table__name\"]").InnerText;
                    var      url      = node.SelectSingleNode(".//a").GetAttributeValue("href", string.Empty);
                    Champion champion = new Champion()
                    {
                        Index = Convert.ToInt32(index),
                        Name  = name,
                        Url   = url
                    };
                    champions.Add(champion);
                }
                property.SetValue(championInfos, champions);
            }
            return(championInfos);
        }