Esempio n. 1
0
        private static void PageCompleted(int page, IReadOnlyList <RealEstate> estates)
        {
            var db = AppContext.Resolve <RealEstateModel>();

            foreach (var estate in estates)
            {
                db.RealEstates.Add(estate);
            }
            db.SaveChanges();
            Console.WriteLine($"Page {page} completed.");
        }
Esempio n. 2
0
        public RealEstate Scrape(string link)
        {
            var driver = AppContext.Resolve <ChromeDriver>();

            driver.Navigate().GoToUrl(link);

            var estate = new RealEstate
            {
                Description = driver.FindElementByXPath(DescriptionXPath)?.Text?.Trim(),
                Price       = driver.FindElementByXPath(PriceXPath).Text.Split(',')[0].ToPrice(),
                Properties  = new List <Property>()
            };

            void Parse(IWebElement dl)
            {
                estate.Properties.Add
                (
                    new Property
                {
                    Name       = dl.FindElement(By.TagName("dt")).Text.Trim().Replace(":", string.Empty),
                    Value      = dl.FindElement(By.TagName("dd")).Text.Trim(),
                    RealEstate = estate
                }
                );
            }

            foreach (var dl in driver.FindElementsByXPath(PropRegion1XPath))
            {
                Parse(dl);
            }
            foreach (var dl in driver.FindElementsByXPath(PropRegion2XPath))
            {
                Parse(dl);
            }

            return(estate);
        }
Esempio n. 3
0
        private static void DeleteDatabase()
        {
            var db = AppContext.Resolve <RealEstateModel>();

            db.Database.Delete();
        }