public void Register_Clear() { try { _driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30)); _driver.Navigate().GoToUrl("http://localhost:5000/Login/Register"); IWebElement btnreset = _driver.FindElementById("btnhtclear"); _driver.ExecuteScript("arguments[0].click();", btnreset); IWebElement txtfname = _driver.FindElement(By.Id("Fname")); IWebElement txtlname = _driver.FindElement(By.Id("Lname")); IWebElement txtphone = _driver.FindElement(By.Id("Phone")); IWebElement txtmail = _driver.FindElement(By.Id("EmailID")); IWebElement txtaddress = _driver.FindElement(By.Id("Address")); IWebElement txtpass = _driver.FindElement(By.Id("Password")); IWebElement txtconpass = _driver.FindElement(By.Id("ConfirmPassword")); IWebElement chkadmin = _driver.FindElement(By.Id("IsAdmin")); Assert.AreEqual(string.Empty, txtfname.GetAttribute("value")); Assert.AreEqual(string.Empty, txtlname.GetAttribute("value")); Assert.AreEqual(string.Empty, txtphone.GetAttribute("value")); Assert.AreEqual(string.Empty, txtmail.GetAttribute("value")); Assert.AreEqual(string.Empty, txtaddress.GetAttribute("value")); Assert.AreEqual(string.Empty, txtpass.GetAttribute("value")); Assert.AreEqual(string.Empty, txtconpass.GetAttribute("value")); Console.Out.WriteLine("Reset button functionality is succeed"); } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } }
private static List <PropertySchool> GetSchools(PhantomJSDriver driver, long ID) { try { string Type = String.Empty; //у нас три типа школ, по умолчанию открывается начальная List <PropertySchool> schools = new List <PropertySchool>(); driver.ExecuteScript("document.querySelector('#schoolsCard .clickable').click()"); //открываем список школ, чтобы он прогрузился System.Threading.Thread.Sleep(1000); for (int i = 0; i < 3; i++) { driver.ExecuteScript(String.Format("document.querySelectorAll('div.mbl.schoolListContainer > div > ul > li > div')[{0}].click()", i)); //нажимаем на кнопку с нуным списком школ switch (i) { case 0: Type = Constants.SchoolType.Elementary; break; case 1: Type = Constants.SchoolType.Middle; break; case 2: Type = Constants.SchoolType.HighSchool; break; } System.Threading.Thread.Sleep(1000); var schoolsList = driver.FindElementsByCssSelector(".line.pls.bbs.pvm"); //выбираем список foreach (var school in schoolsList) { PropertySchool temp = new PropertySchool(); temp.homeID = ID; temp.Type = Type; temp.SchoolName = school.FindElement(By.CssSelector("a")).Text; temp.Grades = school.FindElement(By.CssSelector(".line > div")).Text.Replace("Grades: ", String.Empty); temp.Distance = Convert.ToDouble(school.FindElement(By.CssSelector(".line > div:nth-child(2)")).Text.Replace(" mi", String.Empty)); temp.Address = school.FindElement(By.CssSelector(".typeLowlight")).Text; temp.Rank = school.FindElement(By.CssSelector(".txtC")).Text; } } return(schools); } catch (Exception ex) { Console.WriteLine("Не удалось получить список школ: {}, {}", ex.Message, ex.StackTrace); return(null); throw; } }
static void Main(string[] args) { var url = "https://passport.cnblogs.com/user/signin"; var driver1 = new PhantomJSDriver(GetPhantomJSDriverService()); driver1.Navigate().GoToUrl(url); if (driver1.Title == "用户登录 - 博客园") { driver1.FindElement(By.Id("input1")).SendKeys("xielongbao"); driver1.FindElement(By.Id("input2")).SendKeys("1234"); driver1.FindElement(By.Id("signin")).Click(); } driver1.GetScreenshot().SaveAsFile(@"C:\aa.png", ScreenshotImageFormat.Png); var o = driver1.ExecuteScript("$('#signin').val('dsa')"); Console.WriteLine(driver1.PageSource); driver1.Navigate().GoToUrl(url); Console.WriteLine(driver1.PageSource); IWebDriver driver2 = new PhantomJSDriver(GetPhantomJSDriverService()); driver2.Navigate().GoToUrl("https://home.cnblogs.com/"); Console.WriteLine(driver2.PageSource); Console.WriteLine(driver1.PageSource); Console.Read(); }
private void SubmitBtn_Click(object sender, EventArgs e) { if (MainGrpBox.Controls.OfType <CheckBox>().Where(x => x.Checked).Count() != 2) { MessageBox.Show("Select 2 values please.", "Otaku Time"); return; } string values = String.Join(",", MainGrpBox.Controls.OfType <CheckBox>().Where(x => x.Checked).Select(x => x.Tag)); _Driver.ExecuteScript($"document.getElementById('answerCap').setAttribute('value','{values}')"); _Driver.FindElementById("formVerify").Submit(); if (_Driver.Title == "http://kissanime.ru/Special/AreYouHuman2") //user is wrong. So much for user interaction. { //restart the process. foreach (CheckBox Chk in MainGrpBox.Controls.Cast <CheckBox>()) { Chk.Checked = false; } _Driver.Navigate().GoToUrl(_Url); RenderScreen(); } else { DialogResult = DialogResult.OK; Close(); } }
private static List <PropertyCrime> GetCrimes(PhantomJSDriver driver, long ID) { try { List <PropertyCrime> crimes = new List <PropertyCrime>(); CultureInfo ci = new System.Globalization.CultureInfo("en-US"); driver.ExecuteScript("window.scroll(0, document.querySelector('#nearbySubtitle').offsetTop + 500);"); System.Threading.Thread.Sleep(2000); //Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile("D:\\ScreenShot.png",System.Drawing.Imaging.ImageFormat.Png); var crimesList = driver.FindElementsByCssSelector("div.crimeDataList.bbs.mbs > table > tbody > tr"); foreach (var crime in crimesList) { PropertyCrime temp = new PropertyCrime(); temp.Date = Convert.ToDateTime(crime.FindElement(By.CssSelector("td:nth-child(1) > div")).Text, ci); temp.Type = crime.FindElement(By.CssSelector("td:nth-child(2) > div")).Text; temp.Description = crime.FindElement(By.CssSelector("td:nth-child(3) > div")).Text; temp.HomeId = ID; crimes.Add(temp); } return(crimes); } catch (Exception ex) { Console.WriteLine("Не удалось получить список преступлений: {}, {}", ex.Message, ex.StackTrace); return(null); throw; } }
/// <summary> /// 无头浏览器 /// </summary> /// <param name="urlInfo"></param> /// <returns></returns> private string GetPhantomJsResult(UrlInfo urlInfo) { var pageSource = string.Empty; var _service = Settings._service; var _options = Settings._options; if (_service == null || _service == null) { Console.WriteLine("使用PhantomJsMode请先Settings.InitPhantomJs()"); } var driver = new PhantomJSDriver(_service, _options);//实例化PhantomJS的WebDriver try { ///默认为settings的设置 SeleniumScript script = Settings.script; SeleniumOperation operation = Settings.operation; if (urlInfo.script != null) { script = urlInfo.script; } if (urlInfo.operation != null) { operation = urlInfo.operation; } var watch = DateTime.Now; driver.Navigate().GoToUrl(urlInfo.UrlString);//请求URL地址 if (script != null) { driver.ExecuteScript(script.Code, script.Args); //执行Javascript代码 } if (operation.Action != null) { operation.Action.Invoke(driver); } var driverWait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(operation.Timeout));//设置超时时间为x毫秒 if (operation.Condition != null) { driverWait.Until(operation.Condition); } var threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; //获取当前任务线程ID var milliseconds = DateTime.Now.Subtract(watch).Milliseconds; //获取请求执行时间; pageSource = driver.PageSource; //获取网页Dom结构 return(pageSource); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new Exception("执行GetPhantomJsResult出错"); } finally { driver.Close(); driver.Quit(); } return(pageSource); }
public void SetUp() { if (string.IsNullOrEmpty(Url)) { throw new Exception("URL Cannot be empty"); } driver.Navigate().GoToUrl(Url); driver.ExecuteScript("$.fx.off = true"); }
public async Task StartPages(Uri uri, Script script, Operation operation, Func <IWebDriver, bool> nextPage) { await Task.Run(() => { Onstart(this, new OnStartEventArgs(uri)); //触发启动的事件 var driver = new PhantomJSDriver(_service, _options); //实例化PhantomJS的WebDriver try { var watch = DateTime.Now; driver.Navigate().GoToUrl(uri.ToString());//请求URL地址 if (script != null) { driver.ExecuteScript(script.Code, script.Args); //执行Javascript代码 } var threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; //获取当前任务线程ID P1: var milliseconds = (int)DateTime.Now.Subtract(watch).TotalMilliseconds; //获取请求执行时间; var pageSource = driver.PageSource; //获取网页Dom结构 OnCompleted(this, new OnCompletedEventArgs(uri, threadId, pageSource, milliseconds, driver)); if (nextPage.Invoke(driver)) { watch = DateTime.Now; if (operation.Action != null) { operation.Action.Invoke(driver); } var driverWait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(operation.Timeout));//设置超时时间为x毫秒 if (SleepTimeWait > 10) { System.Threading.Thread.Sleep(SleepTimeWait); } if (operation.Condition != null) { driverWait.Until(operation.Condition); } goto P1; } OnTotleCompleted(this, new EventArgs()); } catch (Exception ex) { OnException(this, new OnExcetionEventArgs(uri, ex)); } finally { driver.Close(); driver.Quit(); } }); }
/// <summary> /// 高级爬虫 /// </summary> /// <param name="uri"></param> /// <param name="script"></param> /// <param name="operation"></param> /// <returns></returns> public async Task Start(Uri uri, Script script, Operation operation, bool Closed = true) { await Task.Run(() => { if (OnStrart != null) { this.OnStrart(this, new OnStartEventArgs(uri)); } Driver = new PhantomJSDriver(_service, _options); try{ Driver.Navigate().GoToUrl(uri); var watch = DateTime.Now; if (script != null) { Driver.ExecuteScript(script.Code, script.Args); } if (operation.Action != null) { operation.Action.Invoke(Driver); } var driverWait = new WebDriverWait(Driver, TimeSpan.FromMilliseconds(operation.TimeOut)); if (operation.Condition != null) { driverWait.Until(operation.Condition); } var ThreadId = Thread.CurrentThread.ManagedThreadId; var milliseconds = DateTime.Now.Subtract(watch).Milliseconds; var pageSoure = Driver.PageSource; if (this.OnCompleted != null) { this.OnCompleted(this, new OnCompletedEventArgs(uri, ThreadId, milliseconds, pageSoure, Driver)); } } catch (Exception ex) { if (this.OnError != null) { this.OnError(this, new OnErrorEventArgs(uri, ex)); } } finally { if (Closed) { Driver.Close(); Driver.Quit(); } } }); }
/// <summary> /// 高级爬虫 /// </summary> /// <param name="uri">抓取地址URL</param> /// <param name="script">要执行的Javascript脚本代码</param> /// <param name="operation">要执行的页面操作</param> /// <returns></returns> public async Task Start(Uri uri, Script script, Operation operation) { await Task.Run(() => { if (OnStart != null) { this.OnStart(this, new OnStartEventArgs(uri)); } var driver = new PhantomJSDriver(_service, _options);//实例化PhantomJS的WebDriver try { var watch = DateTime.Now; driver.Navigate().GoToUrl(uri.ToString());//请求URL地址 if (script != null) { driver.ExecuteScript(script.Code, script.Args); //执行Javascript代码 } if (operation.Action != null) { operation.Action.Invoke(driver); } var driverWait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(operation.Timeout));//设置超时时间为x毫秒 if (operation.Condition != null) { driverWait.Until(operation.Condition); } var threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; //获取当前任务线程ID var milliseconds = DateTime.Now.Subtract(watch).Milliseconds; //获取请求执行时间; var pageSource = driver.PageSource; //获取网页Dom结构 if (this.OnCompleted != null) { this.OnCompleted.Invoke(this, new OnCompletedEventArgs(uri, threadId, milliseconds, pageSource, driver)); } } catch (Exception ex) { if (this.OnError != null) { this.OnError.Invoke(this, new OnErrorEventArgs(uri, ex)); } } finally { driver.Close(); driver.Quit(); } }); }
private void ExecuteScript(Script script, PhantomJSDriver driver) { int times = 1; if (script.FetchModel == 5) { times = script.ActionTimes; } for (int i = 0; i < times; i++) { driver.ExecuteScript(script.Code, script.Args); var driverWait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(script.Timeout)); if (script.Condition != null) { driverWait.Until(script.Condition); } } }
/// <summary> /// 高级爬虫 /// </summary> /// <param name="uri">抓取地址URL</param> /// <param name="script">要执行的Javascript脚本代码</param> /// <param name="operation">要执行的页面操作</param> /// <returns></returns> public OnCompletedEventArgs Start(Uri uri, string name, Operation operation, ref string pageSource, Script script = null) { if (OnStart != null) { this.OnStart(this, new OnStartEventArgs(uri)); } OnCompletedEventArgs result = null; var drives = new ChromeDriver(_chromeDriverService, _chromeOptions); var driver = new PhantomJSDriver(_service, _options);//实例化PhantomJS的WebDriver try { var watch = DateTime.Now; drives.Navigate().GoToUrl(uri.ToString());//请求URL地址 if (script != null) { driver.ExecuteScript(script.Code, script.Args); //执行Javascript代码 } if (operation != null && operation.Action != null) { operation.Action.Invoke(driver); } var driverWait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(operation.Timeout));//设置超时时间为x毫秒 if (operation.Condition != null) { driverWait.Until(operation.Condition); } var threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; //获取当前任务线程ID var milliseconds = DateTime.Now.Subtract(watch).Milliseconds; //获取请求执行时间; pageSource = drives.PageSource; //获取网页Dom结构 result = new OnCompletedEventArgs(uri, threadId, milliseconds, pageSource, drives, name); //this.OnCompleted?.Invoke(this, new OnCompletedEventArgs(uri, threadId, milliseconds, pageSource, driver,name)); } catch (Exception ex) { this.OnError?.Invoke(this, new OnErrorEventArgs(uri, ex)); //throw ex; } return(result); }
/// <summary> /// 异步创建爬虫 /// </summary> /// <param name="uri">爬虫URL地址</param> /// <param name="proxy">代理服务器</param> /// <returns>网页源代码</returns> public async Task StartAsync(Uri uri, Script script, Operation operation, CrawlerPartConfig cpc) { await Task.Run(() => { try { Semaphore.Wait(); //OnStart?.Invoke(this, new OnStartEventArgs(uri)); var _service = PhantomJSDriverService.CreateDefaultService(); _service.LoadImages = false; var _option = new PhantomJSOptions(); var driver = new PhantomJSDriver(_service, _option); try { //WriteLog.InsertLogs(uri.ToString(), "步骤零"); var watch = DateTime.Now; driver.Navigate().GoToUrl(uri.ToString()); if (script != null) { driver.ExecuteScript(script.Code, script.Args); } if (operation != null) { ExecuteAction(operation, driver); } var threadId = Thread.CurrentThread.ManagedThreadId; var seconds = Convert.ToInt32(DateTime.Now.Subtract(watch).TotalSeconds); //WriteLog.InsertLogs(uri.ToString(), "步骤一"); //打开网页时间过长可能导致driver被垃圾回收,限制为30秒 if (seconds < 30) { News news = GetNews(driver, cpc, uri, threadId, seconds); OnCompleted?.Invoke(this, new OnCompletedEventArgs(news)); //OnCompleted?.Invoke(this, new OnCompletedEventArgs(uri, threadId, milliseconds, pageSource, driver, cpc)); } else { WriteLog.InsertLogs(uri.ToString(), "打开网页超时"); if (driver != null) { driver.Quit(); driver = null; //WriteLog.InsertLogs(uri.ToString(), "结束"); } } } catch (Exception ex) { OnError?.Invoke(this, new OnErrorEventArgs(uri, ex)); //WriteLog.InsertLogs(uri.ToString(), ex.Message); } finally { if (driver != null) { driver.Quit(); //WriteLog.InsertLogs(uri.ToString(), "结束"); } } } catch (Exception ex) { OnError?.Invoke(this, new OnErrorEventArgs(uri, ex)); //WriteLog.InsertLogs(uri.ToString(), ex.Message); } finally { Semaphore.Release(); } }); }
public override void DownloadFile(string temporaryFilePath, ILogger logger) { logger?.Info("Downloading account statements from Easybank ..."); using (var driverService = PhantomJSDriverService.CreateDefaultService()) { driverService.HideCommandPromptWindow = true; using (var driver = new PhantomJSDriver(driverService)) { driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(60)); driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(60)); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(60)); try { logger?.Trace("Opening Easybank homepage ..."); driver.Navigate().GoToUrl("https://ebanking.easybank.at"); Screenshot(driver, "Easybank-1", logger); logger?.Trace("Filling login credentials ..."); driver.FindElementById("lof5").SendKeys(_configuration.Verfuegernummer); driver.FindElementById("lof9").SendKeys(_configuration.Pin); driver.FindElementByLinkText("Login").Click(); Screenshot(driver, "Easybank-2", logger); logger?.Trace("Loading account overview ..."); driver.FindElementByLinkText(_configuration.Kontonummer).Click(); Screenshot(driver, "Easybank-3", logger); logger?.Info("Injecting & executing JavaScript ..."); const string script = "var resultField = $('<pre />').attr('id', 'csv_result');" + "var form = document.transactionSearchForm;" + "form.csv.value = 'true';" + "$.ajax({ url: $(form).attr('action')," + "type: 'post'," + "data: $(form).serialize()," + "error: function(xhr, status, error) {" + "$('body').html('').append(resultField);" + "resultField.html('AJAX request failed: ' + status + ' / ' + error);" + "}," + "success: function(response) {" + "$('body').html('').append(resultField);" + "resultField.html(response);" + "}});"; driver.ExecuteScript(script); logger?.Trace("Loading file content from page and saving to {0} ...", temporaryFilePath); var text = driver.FindElementById("csv_result").Text; Screenshot(driver, "Easybank-4", logger); using (var writer = new StreamWriter(temporaryFilePath, false, Encoding.UTF8)) { writer.Write(text); } logger?.Trace("Download completed."); } catch (Exception ex) { logger?.Error("Unable to download from Easybank: " + ex); } finally { driver.Quit(); } } } }
public void Transferee_Housingpage_ShouldRemoveProperty() { help.initialsteps(); orders = help.getOrders(); for (int i = 0; i < orders.Count(); i++) { if (i == 3) { break; } var order_id = orders.ElementAt(help.GetRandomNo(orders)).GetAttribute("data-order-id"); //var order_id = orders.ElementAt(i).GetAttribute("data-order-id"); WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10)); var db_order = _unitOfWork.Orders.GetOrderById(order_id); //_driver.Navigate().GoToUrl(this.baseURL + "/Orders/Transferee/4ec37167-a6a6-4900-9d4f-17568c0c15cb#housing"); _driver.Navigate().GoToUrl(this.baseURL + "/Orders/Transferee/" + order_id + "#housing"); help.delay(800); var before_properties = db_order.HomeFinding.HomeFindingProperties.Count(x => x.Deleted == false); IList <IWebElement> list_properties = _driver.FindElements(By.Id("Listproperties")); if (db_order.HomeFinding != null && list_properties.Count > 0 && !help.GetElement(_driver, By.Id("housingsectionTitle"), 10).Equals("Selected Home")) { //foreach (var a in list_properties) //{ //var aa = a.Text; // if (list_properties.First().Text.IndexOf("Singheshwar") != -1) //{ // a.Click(); list_properties.First().Click(); help.delay(800); help.GetElementClick(_driver, By.Id("removeProperty"), 10).Click(); if (_driver.GetType() == typeof(PhantomJSDriver)) { PhantomJSDriver phantom = (PhantomJSDriver)_driver; phantom.ExecuteScript("window.alert = function(){}"); phantom.ExecuteScript("window.confirm = function(){return true;}"); } else { _driver.SwitchTo().Alert().Accept(); } IList <IWebElement> after_properties = _driver.FindElements(By.Id("Listproperties")); //Xunit.Assert.Equal(before_properties, after_properties.Count()); list_properties = after_properties; //_driver.Navigate().Refresh(); //} //} } _driver.Navigate().GoToUrl(this.baseURL + "/Orders"); orders = _driver.FindElements(By.Id("rowclickableorderRow")); } //Xunit.Assert.Equal(orders.Count(), order_db.Count()); help.Logout(); }
public static bool ParseProperty(string link) { PhantomJSDriver driver = CreateDriver(); try { if (driver.SessionId == null) { driver = CreateDriver(); } //переход по стартовой ссылке города while (true) { try { driver.Navigate().GoToUrl(link); break; } catch (Exception ex) { logger.Trace(ex, "Ошибка получения страницы, время ожидания истекло. {0},{1}", ex.Message, ex.StackTrace); logger.Error(ex, "Ошибка получения страницы, время ожидания истекло. {0},{1}", ex.Message, ex.StackTrace); driver.Quit(); driver = CreateDriver(); } } if (!link.Contains("sold")) { Console.WriteLine("Property isn't sold." + link); logger.Info("Property isn't sold. {0}", link); return(false); } Dictionary <string, object> mainProperties = driver.ExecuteScript("return trulia.pdp.propertyJSON") as Dictionary <string, object>; HomeProperty hp = new HomeProperty(); try { hp.addressForDisplay = (string)mainProperties[Constants.HomePropertyJSObjectKeys.addressForDisplay]; } catch { } try { hp.addressForLeadForm = (string)mainProperties[Constants.HomePropertyJSObjectKeys.addressForLeadForm]; } catch { } try { hp.agentName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.agentName]; } catch { } try { hp.apartmentNumber = (string)mainProperties[Constants.HomePropertyJSObjectKeys.apartmentNumber]; } catch { } try { hp.builderCommunityId = (string)mainProperties[Constants.HomePropertyJSObjectKeys.builderCommunityId]; } catch { } try { hp.builderName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.builderName]; } catch { } try { hp.city = (string)mainProperties[Constants.HomePropertyJSObjectKeys.city]; } catch { } try { hp.communityFloors = null; } catch { }//!!! try { hp.communityOtherFeatures = null; } catch { } //!!! try { hp.county = (string)mainProperties[Constants.HomePropertyJSObjectKeys.county]; } catch { } try { hp.countyFIPS = (string)mainProperties[Constants.HomePropertyJSObjectKeys.countyFIPS]; } catch { } try { hp.dataPhotos = (string)mainProperties[Constants.HomePropertyJSObjectKeys.dataPhotos]; } catch { } try { hp.description = driver.FindElementByCssSelector("#corepropertydescription").Text; } catch { } //!!!!!!!!!!!!!!!! try { hp.directLink = link; } catch { } try { hp.features = driver.FindElementByCssSelector(".mtl").Text; } catch { } //!!!!!!!!!! try { hp.formattedBedAndBath = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedBedAndBath]; } catch { } try { hp.formattedLotSize = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedLotSize]; } catch { } try { hp.formattedPrice = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedPrice]; } catch { } try { hp.formattedSqft = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedSqft]; } catch { } try { hp.hasOpenHouse = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.hasOpenHouse]; } catch { } try { hp.hasPhotos = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.hasPhotos]; } catch { } try { hp.HomeDetails = null; } catch { } //!!!! try { hp.idealIncome = -1; } catch { } //!!!! try { hp.indexSource = (string)mainProperties[Constants.HomePropertyJSObjectKeys.indexSource]; } catch { } try { hp.isBuilder = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isBuilder]; } catch { } try { hp.isBuilderCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isBuilderCommunity]; } catch { } try { hp.isForeclosure = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isForeclosure]; } catch { } try { hp.isForSale = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isForSale]; } catch { } try { hp.isPlan = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isPlan]; } catch { } try { hp.isPromotedCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isPromotedCommunity]; } catch { } try { hp.isRealogy = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRealogy]; } catch { } try { hp.isRental = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRental]; } catch { } try { hp.isRentalCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRentalCommunity]; } catch { } try { hp.isSpec = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSpec]; } catch { } try { hp.isSrpFeatured = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSrpFeatured]; } catch { } try { hp.isStudio = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isStudio]; } catch { } try { hp.isSubsidized = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSubsidized]; } catch { } try { hp.lastSaleDate = (string)mainProperties[Constants.HomePropertyJSObjectKeys.lastSaleDate]; } catch { } try { hp.latitude = (double)mainProperties[Constants.HomePropertyJSObjectKeys.latitude]; } catch { } try { hp.listingId = (long)mainProperties[Constants.HomePropertyJSObjectKeys.listingId]; } catch { } try { hp.listingType = (string)mainProperties[Constants.HomePropertyJSObjectKeys.listingType]; } catch { } try { hp.locationId = (string)mainProperties[Constants.HomePropertyJSObjectKeys.locationId]; } catch { } try { hp.longitude = (double)mainProperties[Constants.HomePropertyJSObjectKeys.longitude]; } catch { } try { hp.metaInfo = null; } catch { }//!!!! try { hp.numBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBathrooms]); } catch { } try { hp.numBedrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBedrooms]); } catch { } try { hp.numBeds = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBeds]); } catch { } try { hp.numFullBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numFullBathrooms]); } catch { } try { hp.numPartialBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numPartialBathrooms]); } catch { } try { hp.pdpURL = (string)mainProperties[Constants.HomePropertyJSObjectKeys.pdpURL]; } catch { } try { hp.PetsAllowed = null; } catch { } // !!!!!!!!!!! try { hp.phone = null; } catch { } //!!!!!!! try { hp.postId = (long)mainProperties[Constants.HomePropertyJSObjectKeys.postId]; } catch { } try { hp.pricePerSqft = (string)mainProperties[Constants.HomePropertyJSObjectKeys.pricePerSqft]; } catch { } try { hp.PublicRecords = null; } catch { }//!!!!!! try { hp.rentalPartnerDisplayText = (string)mainProperties[Constants.HomePropertyJSObjectKeys.rentalPartnerDisplayText]; } catch { } try { hp.type = (string)mainProperties[Constants.HomePropertyJSObjectKeys.type]; } catch { } try { hp.typeDisplay = (string)mainProperties[Constants.HomePropertyJSObjectKeys.typeDisplay]; } catch { } try { hp.shortDescription = (string)mainProperties[Constants.HomePropertyJSObjectKeys.shortDescription]; } catch { } try { hp.sqft = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.sqft]); } catch { } try { hp.stateCode = (string)mainProperties[Constants.HomePropertyJSObjectKeys.stateCode]; } catch { } try { hp.stateName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.stateName]; } catch { } try { hp.status = (string)mainProperties[Constants.HomePropertyJSObjectKeys.status]; } catch { } try { hp.street = (string)mainProperties[Constants.HomePropertyJSObjectKeys.street]; } catch { } try { hp.streetNumber = (string)mainProperties[Constants.HomePropertyJSObjectKeys.streetNumber]; } catch { } try { hp.yearBuilt = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.yearBuilt]); } catch { } try { hp.zipCode = (string)mainProperties[Constants.HomePropertyJSObjectKeys.zipCode]; } catch { } try { hp.ComparablesJSON = (string)driver.ExecuteScript("return JSON.stringify(trulia.pdp.comparableProperties)"); } catch { } long ID = hp.InsertToDb(); if (ID > 0) { List <PropertyCrime> crimes = GetCrimes(driver, ID); crimes.ForEach(crime => crime.InsertToDb()); } if (ID > 0) { List <PropertySchool> schools = GetSchools(driver, ID); schools.ForEach(school => school.InsertToDb()); } return(true); //все прошло успешно } catch (OpenQA.Selenium.WebDriverException ex) { logger.Error(ex, "Возникло исключение web-драйвера: {1}, {0}", ex.StackTrace, ex.Message); return(false); } catch (Exception ex) { logger.Error(ex, "Возникло неизвестное исключение: {1}, {0}", ex.StackTrace, ex.Message); return(false); } finally { driver.Quit(); } }