Beispiel #1
0
        public OfertyDomWebsite() : base("www.oferty-dom.pl", "/szukaj/{" +
                                         pageNumber +
                                         "}.html?sort=domyslne&pageLimit=40&propertyType={" +
                                         propertyType +
                                         "}&advertisementType={" +
                                         advertisementType +
                                         "}&city=&dzielnica=&powiat=" +
                                         "&province={" +
                                         province,
                                         "Oferty dom")
        {
            try
            {
                //Add property types
                PropertyTypeIdMap.Add(Enums.PropertyType.FLAT, "6");
                PropertyTypeIdMap.Add(Enums.PropertyType.LAND, "2");
                PropertyTypeIdMap.Add(Enums.PropertyType.GARAGE, "3");
                PropertyTypeIdMap.Add(Enums.PropertyType.PREMISE, "5");
                PropertyTypeIdMap.Add(Enums.PropertyType.ROOM, "11");
                PropertyTypeIdMap.Add(Enums.PropertyType.ELSE, "10");
                PropertyTypeIdMap.Add(Enums.PropertyType.HOUSE, "1");

                //Add provinces
                ProvinceIdMap.Add(Province.FromString("Dolnośląskie"), "1");
                ProvinceIdMap.Add(Province.FromString("Kujawsko-pomorskie"), "2");
                ProvinceIdMap.Add(Province.FromString("Lubelskie"), "3");
                ProvinceIdMap.Add(Province.FromString("Lubuskie"), "4");
                ProvinceIdMap.Add(Province.FromString("Łódzkie"), "5");
                ProvinceIdMap.Add(Province.FromString("Małopolskie"), "6");
                ProvinceIdMap.Add(Province.FromString("Mazowieckie"), "7");
                ProvinceIdMap.Add(Province.FromString("Opolskie"), "8");
                ProvinceIdMap.Add(Province.FromString("Podkarpackie"), "9");
                ProvinceIdMap.Add(Province.FromString("Podlaskie"), "10");
                ProvinceIdMap.Add(Province.FromString("Pomorskie"), "11");
                ProvinceIdMap.Add(Province.FromString("Śląskie"), "12");
                ProvinceIdMap.Add(Province.FromString("Świętokrzyskie"), "13");
                ProvinceIdMap.Add(Province.FromString("Warmińsko-mazurskie"), "14");
                ProvinceIdMap.Add(Province.FromString("Wielkopolskie"), "15");
                ProvinceIdMap.Add(Province.FromString("Zachodniopomorskie"), "16");

                //Add advertisement types
                AdvertisementTypeIdMap.Add(Enums.AdvertisementType.RENT, "4");
                AdvertisementTypeIdMap.Add(Enums.AdvertisementType.SALE, "1");
                AdvertisementTypeIdMap.Add(Enums.AdvertisementType.ALL, "6");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                //Some error in spelling of provinces
            }
        }
Beispiel #2
0
        public ActionResult Search(string city = "all", string propType = "all", string province = "all", string advType = "all", int page = 1)
        {
            List <RealEstateOfferModel> list = null;

            try
            {
                if (city == "")
                {
                    city = "all";
                }
                RealEstateOfferRequestModel requestModel = new RealEstateOfferRequestModel(Province.FromString(province), City.FromString(city), PropertyType.FromString(propType), AdvertisementType.FromString(advType));
                list = WebsitesManagement.GetFilteredOffers(requestModel);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                TempData["Error"] = ex.Message;
            }
            ViewBag.cityFilter          = city;
            ViewBag.propertyFilter      = propType;
            ViewBag.provinceFilter      = province;
            ViewBag.advertisementFilter = advType;
            ViewBag.cities    = DataManagement.getCities();
            ViewBag.provinces = DataManagement.getProvinces();
            if (list == null)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(list.ToPagedList(page, 10)));
            }
        }
Beispiel #3
0
        public async override void GetRealEstateOffers()
        {
            foreach (var propType in Enums.PropertyType.Values)
            {
                foreach (var province in Province.PROVINCES)
                {
                    try
                    {
                        RealEstateOfferRequestModel model = new RealEstateOfferRequestModel(Province.FromString(province.Name), City.ALL,
                                                                                            Enums.PropertyType.FromString(propType.Name), Enums.AdvertisementType.ALL);
                        string request       = FormatRequestString(model);
                        string offersWebsite = ReadWebsite(request);
                        if (offersWebsite != null)
                        {
                            //Parse offers from first page
                            await ParseOffersFromHtml(offersWebsite);

                            //Get number of pages left to check
                            string offerTotalPages = offersWebsite.Substring(offersWebsite.LastIndexOf("golink('/oferta/search/")
                                                                             + "golink('/oferta/search/".Length);
                            offerTotalPages = offerTotalPages.Remove(offerTotalPages.IndexOf(".html"));
                            int count = Int32.Parse(offerTotalPages);
                            for (int i = 2; i < count; i++)
                            {
                                //Parse offers from rest of pages
                                model.PageNumber++;
                                request       = FormatRequestString(model);
                                offersWebsite = ReadWebsite(request);
                                await ParseOffersFromHtml(offersWebsite);
                            }
                        }
                        else
                        {
                            //Invalid html
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                }
            }
        }
        private RealEstateOfferModel ParseSingleOfferFromHtml(string webAddress, string a_html)
        {
            RealEstateOfferModel offer = new RealEstateOfferModel(webAddress);
            string currentState        = null;

            try
            {
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(a_html);
                //Get offer images
                var offerImagesNode = document.DocumentNode.SelectNodes(offerImagesInHtml);
                foreach (var imageNode in offerImagesNode)
                {
                    string address = imageNode.GetAttributeValue("content", null);
                    if (address != null)
                    {
                        offer.ImagesAddresses.Add(address);
                    }
                }
                currentState = "offer images";
                //Get offer title
                var offerTitleNode = document.DocumentNode.SelectSingleNode(offerTitleInHtml);
                offer.Title  = offerTitleNode.InnerText.Trim();
                currentState = "offer title node";

                //Get offer description
                var offerDescriptionNode = document.DocumentNode.SelectSingleNode(offerDescInHtml);
                offer.Description = offerDescriptionNode.InnerText.Trim();
                currentState      = "offer description node";

                //Get offer price
                var offerPriceNode = document.DocumentNode.SelectSingleNode(offerPriceInHtml);
                offer.Price  = ParsePrice(offerPriceNode.GetAttributeValue("content", "0"));
                currentState = "offer price node";

                //Get offer type(advertisement and real estate type)
                var offerTypeNode = document.DocumentNode.SelectSingleNode(offerTypeInHtml);

                var locationNodes = document.DocumentNode.SelectSingleNode(offerLocationInHtml).SelectNodes(".//a");
                currentState = "offer location node";

                string offerProvince = locationNodes[0].InnerText;
                offer.Province = Province.FromString(offerProvince);
                currentState   = "province";

                string offerCity = locationNodes[1].InnerText;
                offer.OfferCity = City.FromString(offerCity);
                if (offer.OfferCity == null || offer.OfferCity == City.INVALID)
                {
                    throw new Exception("City " + offerCity + " could not be parsed");
                }
                currentState = "city";


                string offerType = System.Net.WebUtility.HtmlDecode(offerTypeNode.InnerText.ToLower());
                currentState = "offer type node";

                //Get advertisement type
                if (offerType.Contains("sprzedam"))
                {
                    offer.AdvType = AdvertisementType.SALE;
                }
                else if (offerType.Contains("wynajmę"))
                {
                    offer.AdvType = AdvertisementType.RENT;
                }
                currentState = "advertisement type";

                //Get property type
                if (offerType.Contains("mieszkanie"))
                {
                    offer.PropType = PropertyType.FLAT;
                }
                else if (offerType.Contains("dom"))
                {
                    offer.PropType = PropertyType.HOUSE;
                }
                else if (offerType.Contains("lokal użytkowy"))
                {
                    offer.PropType = PropertyType.PREMISE;
                }
                else if (offerType.Contains("działka"))
                {
                    offer.PropType = PropertyType.LAND;
                }
                else if (offerType.Contains("pokój"))
                {
                    offer.PropType = PropertyType.ROOM;
                }
                else if (offerType.Contains("garaż"))
                {
                    offer.PropType = PropertyType.GARAGE;
                }
                else
                {
                    offer.PropType = PropertyType.INVALID;
                }
                currentState = "property type";
            }
            catch (Exception ex)
            {
                offer = null;
                Debug.WriteLine(currentState);
                Debug.WriteLine(ex);
            }

            return(offer);
        }