public virtual void Inject(IDownloader downloader, ISpider spider, bool pauseBeforeInject = true) { if (!CheckFrequency()) { return; } if (pauseBeforeInject) { spider.Pause(() => { foreach (Cookie cookie in GetCookies(spider)) { downloader.AddCookie(cookie); } spider.Logger.Information("Inject cookies success."); spider.Contiune(); }); } else { foreach (Cookie cookie in GetCookies(spider)) { downloader.AddCookie(cookie); } spider.Logger.Information("Inject cookies success."); } }
public virtual void Inject(ISpider spider, bool stopSpider = true) { if (stopSpider) { spider.Pause(); } spider.Site.Cookies = GetCookies(spider.Site); spider.Log("注入 Cookies 成功。", LogLevel.Info); if (stopSpider) { spider.Contiune(); } }
/// <summary> /// 执行注入Cookie的操作 /// </summary> /// <param name="downloader">下载器</param> /// <param name="spider">需要注入Cookie的爬虫</param> /// <param name="pauseBeforeInject">注入Cookie前是否先暂停爬虫</param> public override void Inject(IDownloader downloader, ISpider spider, bool pauseBeforeInject = true) { if (Driver == null) { return; } if (!CheckFrequency()) { return; } spider.Pause(() => { Login(); spider.Contiune(); }); }
/// <summary> /// 执行注入Cookie的操作 /// </summary> /// <param name="spider">爬虫</param> /// <param name="pauseBeforeInject">注入Cookie前是否先暂停爬虫</param> public virtual void Inject(ISpider spider, bool pauseBeforeInject = true) { if (pauseBeforeInject) { spider.Pause(() => { spider.Cookies = GetCookies(spider); Logger.AllLog(spider.Identity, "Inject cookies success.", LogLevel.Info); spider.Contiune(); }); } else { spider.Cookies = GetCookies(spider); Logger.AllLog(spider.Identity, "Inject cookies success.", LogLevel.Info); } }
public virtual void Inject(ISpider spider, bool stopSpider = true) { if (stopSpider) { spider.Pause(() => { spider.Site.Cookies = GetCookies(spider); Logger.MyLog(spider.Identity, "Inject cookies success.", LogLevel.Info); spider.Contiune(); }); } else { spider.Site.Cookies = GetCookies(spider); Logger.MyLog(spider.Identity, "Inject cookies success.", LogLevel.Info); } }
protected void RegisterControl(ISpider spider) { if (RedisConnection.Default != null) { try { RedisConnection.Default.Subscriber.Subscribe($"{spider.Identity}", (c, m) => { switch (m) { case "PAUSE": { spider.Pause(); break; } case "CONTINUE": { spider.Contiune(); break; } case "RUNASYNC": { spider.RunAsync(); break; } case "EXIT": { spider.Exit(); break; } } }); } catch (Exception e) { Logger.MyLog(Identity, "Register contol failed.", LogLevel.Error, e); } } }