Exemplo n.º 1
0
        static void Main(string[] args)
        {
            logger.Info("Logger started");

            var    pageUrl      = "https://en.wikipedia.org/wiki/Gallery_of_sovereign_state_flags";
            var    httpDownload = new HttpRequestAndLoad();
            string httpText     = httpDownload.Load(pageUrl);

            var httpParser = new HtmlParser();
            var element    = httpParser.Parse(httpText).DocumentElement;

            var flagsHref = element.SelectNodes(@"//*[@id='mw-content-text']/div/table//table//tr[1]/td[1]/a/img");

            // Async Timer
            using (var timer = new LogWrapTimer())
            {
                var downloadQueue = new DownloadFileQueue()
                {
                    Extension = ".jpg",
                    AsyncMode = false
                };

                downloadQueue.Setup("Flags");

                foreach (IElement flagHref in flagsHref)
                {
                    var urlRelative = flagHref.GetAttribute("src");
                    var urlAbsolute = new Uri(new Uri(pageUrl), urlRelative);

                    downloadQueue.AddTask(urlAbsolute.AbsoluteUri);
                }

                downloadQueue.Wait();
            }
        }