Exemple #1
0
        private static void Run(Options options)
        {
            var filter = new Filter(options.Host)
            {
                ExcludeAnchors    = options.ExcludeAnchors,
                ExcludeImages     = options.ExcludeImages,
                ExcludeJavaScript = options.ExcludeJavaScript
            };

            var crawler = new Spider {
                Filter = filter
            };

            crawler.OnCompleted += () =>
            {
                Console.WriteLine("Completed");
                Console.ReadKey();
            };

            crawler.OnPageDownloaded += page =>
            {
                File.WriteAllText($@"{options.Target}\{Path.GetFileName(page.Url.LocalPath)}_{Guid.NewGuid()}.html", page.Html);
                Console.WriteLine($"Downloaded: {page.Url}");
            };

            crawler.Enqueue(new Uri($"http://{options.Host}/"));
            crawler.Start();

            Console.WriteLine("Started.");
            Console.ReadLine();
        }