static void Main(string[] args) { Console.WriteLine("商铺采集小程序,管理员QQ 592955699!"); var shopConfig = ShopConfig.LoadConfig(); Console.WriteLine($"商铺账号:{shopConfig.Account}"); Console.WriteLine($"文件地址:{shopConfig.SavePath}"); //注册编码(放在将要指定编码,进行文件解析前) Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); SnifferContext snifferContext = new SnifferContext(); PageConfigManager pageConfigManager = new PageConfigManager(); String path = AppContext.BaseDirectory + "PageConfigs\\ShopConfig.xml"; var configs = pageConfigManager.LoadConfig(path); foreach (var item in configs) { Console.WriteLine($"商铺地址:{item.Url}"); if (item.PageType == PageType.DetailPage) { DetailPage rootDetailPage = new DetailPage(null, item); snifferContext.AddToWaitPages(rootDetailPage); } else { ListPage rootListPage = new ListPage(null, item); snifferContext.AddToWaitPages(rootListPage); Console.WriteLine($"采集页数:{rootListPage.ListPageConfig.MaxPage}"); } } SnifferManager sniffer = new SnifferManager(snifferContext); sniffer.OnPageDoneEventHandler = (page, context) => { Console.WriteLine($"OnPageDoneEventHandler\t\t{page.Url}"); Console.WriteLine($"待处理页面 {context.GetWaitPageCount()} 个"); }; sniffer.OnRootPageDoneEventHandler = (page, context) => { Console.WriteLine($"OnRootPageDoneEventHandler\t{page.Url}"); }; sniffer.OnListUrlPageDoneEventHandler = (page, context) => { Console.WriteLine($"OnListUrlPageDoneEventHandler\t{page.Url}"); }; sniffer.OnListPageDoneEventHandler = (page, context) => { Console.WriteLine($"OnListPageDoneEventHandler\t{page.Url}"); }; //详细页采集完毕,组合生成url待下载 sniffer.OnDetailPageDoneEventHandler = (page, context) => { //Console.WriteLine($"OnDetailPageDoneEventHandler\t{page.Url}"); }; sniffer.Execute(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); ChromeDriver driver = new ChromeDriver(AppContext.BaseDirectory); driver.Manage().Window.Maximize();//窗口最大化,便于脚本执行 driver.Manage().Window.Size = new Size(800, 800); TianyanchaLogin tianyanchaLogin = new TianyanchaLogin(driver); bool login = tianyanchaLogin.Login(); CookieContainer = tianyanchaLogin.CookieContainer; //注册编码(放在将要指定编码,进行文件解析前) Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); SnifferContext context = new SnifferContext(); PageConfigManager pageConfigManager = new PageConfigManager(); String path = AppContext.BaseDirectory + "PageConfigs\\ShopConfig.xml"; var configs = pageConfigManager.LoadConfig(path); foreach (var item in configs) { if (item.PageType == PageType.DetailPage) { DetailPage rootDetailPage = new DetailPage(null, item); context.AddToWaitPages(rootDetailPage); } else { ListPage rootListPage = new ListPage(null, item); context.AddToWaitPages(rootListPage); } } SnifferManager sniffer = new SnifferManager(context); sniffer.OnPageDoneEventHandler = (page) => { Console.WriteLine($"OnPageDoneEventHandler\t\t{page.Url}"); }; sniffer.OnRootPageDoneEventHandler = (page) => { Console.WriteLine($"OnRootPageDoneEventHandler\t{page.Url}"); }; sniffer.OnListUrlPageDoneEventHandler = (page) => { Console.WriteLine($"OnListUrlPageDoneEventHandler\t{page.Url}"); }; sniffer.OnListPageDoneEventHandler = (page) => { Console.WriteLine($"OnListPageDoneEventHandler\t{page.Url}"); }; //详细页采集完毕,组合生成url待下载 sniffer.OnDetailPageDoneEventHandler = (page) => { Console.WriteLine($"OnDetailPageDoneEventHandler\t{page.Url}"); }; sniffer.Execute(); }