static void TestInstanceStatistics() { var avito = new Avito(); var task = new TaskInstanceStatisticsCache { InstanceId = new Guid("8BB27650-462E-497E-B9A5-044AA1C66FAD"), Url = "https://www.avito.ru/podolsk/telefony/iphone_6s_64gb_seryy_kosmos_1259355638", }; FirefoxHelper.ExecuteWithVisual(browser => { browser.Navigate().GoToUrl("https://www.avito.ru/moskva/bytovaya_elektronika"); var stat = avito.GetInstanceStatistics(browser, task); if (stat != null) { var instance = BulletinInstanceHelper.Get(task.InstanceId); instance.Views = stat.Value; BulletinInstanceHelper.Save(instance); } }, null, 100); }
public override int?GetInstanceStatistics(FirefoxDriver driver, TaskInstanceStatisticsCache taskModel) { int?result = null; try { var viewPattern = "class=\"title-info-views[\\s\\S\\r\\n]*?}\">[\\s\\S\\r\\n]*?(\\d+)"; driver.Navigate().GoToUrl(taskModel.Url); WaitPage(driver, 30000, taskModel.Url); var pageSource = driver.PageSource; var rawView = RegexHelper.GetValue(viewPattern, pageSource); var success = Int32.TryParse(rawView, out var viewCount); if (success) { result = viewCount; } } catch (Exception ex) { } return(result); }