private void ProcessLinks() { if (ShareLockLogic) { return; } // if (!ReferenceEquals(ServiceStatus, BaseServicesStatuses.ServiceLaunched)) // { // return; // } if (ReferenceEquals(_tasks, null) || _tasks.Count.Equals(0)) { return; } if (ReferenceEquals(_tasks.Where(t => ReferenceEquals(t.GeneratedUrl, null) || t.GeneratedUrl.Equals(String.Empty)).ToList(), 0)) { return; } ShareLockLogic = true; var tasks = _tasks.Where(t => ReferenceEquals(t.GeneratedUrl, null) || t.GeneratedUrl.Equals(String.Empty)).ToList(); foreach (var task in tasks) { if (!ReferenceEquals(_c, null)) { _c.NavigateToPage(settings.RequestPageUrl); _c.UpdateFieldData("#destinationURL", task.RequestUrl); _c.ExecuteScript("document.getElementById('buildLinkFrm').children[7].children[0].click()"); bool solved = false; int safe = 10; int current = 0; while (!solved && current <= safe) { Thread.Sleep(500); var currentContext = _c.GetDataFromPage(null, "return getUrl(); function getUrl(){return document.getElementById(\"buildLinkFrm\").children[7].children[0].getAttribute(\"value\");}").Trim(); if (currentContext.Equals("Create Custom Link")) { current++; } else { break; } } task.GeneratedUrl = _c.GetDataFromPage(null, "return getUrl(); function getUrl(){return document.getElementById(\"buildLinkFrm\").children[7].children[0].getAttribute(\"value\");}"); lock (locker) { var _selected = _tasks.FirstOrDefault(t => t.RequestUrl.Equals(task.RequestUrl)); if (!ReferenceEquals(_selected, null)) { _selected.GeneratedUrl = _c.GetDataFromPage(null, "return getUrl(); function getUrl(){return document.getElementById(\"buildLinkFrm\").children[7].children[0].getAttribute(\"value\");}"); } } } } ShareLockLogic = false; // ProcessLinks(); }
public WebScrapperBaseCollectionsProcessorEntity FindCollections(WebScrapperBaseCollectionsProcessorEntity strategy) { var _s = new BaseWebDriverStrategy { }; var o = new ChromeOptions(); o.AddArgument("ignore-certificate-errors"); o.AddArgument("disable-infobars"); // o.AddArgument("--headless"); IWebDriverResolver _driver = new ChromeDriverResolver(_s, new Entities.WebScrapperBaseProxyEntity(), strategy.DriverSettings.RequestUrl, _l); if (!_driver.Initialize()) { _l.error($"Fatal: instance {strategy.DriverSettings.RequestUrl} cannot be initialized!"); _driver.Dispose(); return(strategy); } if (!ReferenceEquals(strategy.DriverSettings.TasksList, null) && strategy.DriverSettings.TasksList.Count > 0) { foreach (var task in strategy.DriverSettings.TasksList) { if (task.TaskType.Equals(BaseWebDriverTasksTypes.TaskExecuteScript)) { string source = String.Empty; switch (task.ScriptSourceType) { case WebScrapper.Scrapper.Entities.enums.By.FileSource: source = _f.Read($"{Directory.GetCurrentDirectory()}/Scrapper/Resources/{task.ScriptSource}"); if (ReferenceEquals(source, String.Empty)) { _l.error($"Fatal: cannot load script from file {Directory.GetCurrentDirectory()}/Scrapper/Resources/{task.ScriptSource}"); _driver.Dispose(); return(strategy); } break; case WebScrapper.Scrapper.Entities.enums.By.StringSource: source = task.ScriptSource; break; } string context = _driver.GetDataFromPage(task.RequestElement, source); if (ReferenceEquals(context, String.Empty)) { _l.error($"Chrome driver: fatal, execution script failed, visit application error logs to get more information about problem, script source: {source}"); } try { var l = context.Split("||||").ToList(); strategy.Collections = l; } catch (Exception e) { _l.error($"Error in processing script result: {e.Message} -> {e.StackTrace}"); _driver.Dispose(); return(strategy); } } } } _driver.Dispose(); return(strategy); }