Пример #1
0
        static void Main(string[] args)
        {
            string siteUrl = String.Empty;

            for (int i = 0; i <= args.GetUpperBound(0); i++)
            {
                switch (args[i].ToUpper())
                {
                case "-URL":
                    siteUrl = args[i + 1];
                    i++;
                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unbekannter Parameter" + args[i]);
                    Console.WriteLine("Verwendung : Crawler -Url https://www.siteurl.com");
                    return;
                }
            }

            SiteCrawler siteCrawler = new SiteCrawler(siteUrl);

            siteCrawler.OnPageLoaded       += SiteCrawler_OnPageLoaded;
            siteCrawler.OnErrorLoadingPage += SiteCrawler_OnErrorLoadingPage;
            siteCrawler.StartCrawling();
        }
Пример #2
0
        static void Main(string[] args)
        {
            SiteCrawler crawler = new SiteCrawler();

            crawler.onReport += Crawler_onReport;
            crawler.start();

            // Wait until the crawling ends
            while (!crawler.isDone)
            {
                // Meanwhile watch the keyboard
                if (Console.KeyAvailable)
                {
                    // Check what key was pressed
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                    {
                        crawler.stop();
                    }
                }
                else
                {
                    // No to waste the clock
                    System.Threading.Thread.Sleep(100);
                }
            }

            // Done with it
            Console.WriteLine("Press any key to continue");
            while (!Console.KeyAvailable)
            {
                System.Threading.Thread.Sleep(100);
            }
        }