Exemplo 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.");
        }
Exemplo 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);
        }
Exemplo n.º 3
0
        private static void DeleteDatabase()
        {
            var db = AppContext.Resolve <RealEstateModel>();

            db.Database.Delete();
        }