Esempio n. 1
0
 public static Advert ParseAdvert(String url)
 {
     Advert advert = new Advert();
     wClient.Proxy = null;
     wClient.Encoding = System.Text.Encoding.GetEncoding("utf-8");
     try
     {
         document.LoadHtml(wClient.DownloadString(url));
         if (document != null)
         {
             HtmlNode phone = document.DocumentNode.SelectSingleNode("//*[@id=\"ctl00_ContentPlaceHolder1_contactInfo\"]/tr/td[2]");
             HtmlNode text = document.DocumentNode.SelectSingleNode("//*[@id=\"ctl00_ContentPlaceHolder1_title\"]");
             HtmlNodeCollection owner = document.DocumentNode.SelectNodes("//*[@id=\"ctl00_ContentPlaceHolder1_contactInfo\"]/tr[2]/td");
             if (owner != null)
                 foreach (HtmlNode n in owner)
                 {
                     if (n.InnerText.Contains("Аг") || n.InnerText.Contains("факт") || n.InnerText.Contains("аген") || n.InnerText.Contains("аг"))
                         advert.SetAgent(true);
                 }
             if (phone != null)
             {
                 advert.setPhone(phone.InnerText);
             }
             if (text != null)
             {
                 advert.setHeader(text.InnerText);
             }
         }
     }
     catch
     {
         Console.WriteLine("ERROR    "+url);
     }
     return advert;
 }
Esempio n. 2
0
        // Parsing main table of kvartirant.by and making list of all adverts
        private static List<Advert> CheckAgentAdverts()
        {
            List<Advert> adverts = new List<Advert>();
            for (int i = 1; i < 229; i++)
            {
                if (i < 2)
                {
                    document.LoadHtml(wClient.DownloadString(string.Format("http://www.kvartirant.by/rent/flats/")));
                }
                else
                {
                    document.LoadHtml(wClient.DownloadString(string.Format("http://www.kvartirant.by/rent/flats/page/" + i + "/")));
                }

                if (document.DocumentNode != null)
                {
                    Advert a = new Advert();
                    for (int j = 0; j < 10; j++)
                    {
                        HtmlNodeCollection textAdvert = document.DocumentNode.SelectNodes("//div[@class='txt_box2']/p[2]");
                        HtmlNodeCollection phone = document.DocumentNode.SelectNodes("//div[@class='txt_box2']/p[2]/strong");
                        HtmlNodeCollection price = document.DocumentNode.SelectNodes("//div[@class='price_box']/b");
                        if (textAdvert[j] != null)
                            a.setHeader(textAdvert[j].InnerText);
                        if (phone[j] != null)
                            a.setPhone(phone[j].InnerText);
                        if (price[j] != null)
                            a.setPrice(price[j].InnerText);
                        adverts.Add(a);
                    }
                }
            }
            return adverts;
        }
Esempio n. 3
0
 // Parsing single advert page from irr.by
 private static Advert ParseAdvert(String url)
 {
     wClient.Proxy = null;
     wClient.Encoding = System.Text.Encoding.GetEncoding("utf-8");
     Advert advert = new Advert();
     document.LoadHtml(wClient.DownloadString(string.Format(url)));
     if (document.DocumentNode != null)
     {
         HtmlNode header = document.DocumentNode.SelectSingleNode("/html/body/div[9]/div/div/div/div[3]/div/div[2]/h1");
         HtmlNode price = document.DocumentNode.SelectSingleNode("//*[@id=\"priceSelected\"]");
         if (header != null)
             advert.setHeader(header.InnerText);
         advert.setPhone(ParsePhones());
         if (price != null)
             advert.setPrice(price.InnerText);
     }
     HtmlNode flag = document.DocumentNode.SelectSingleNode("/html/body/div[9]/div/div/div/div[4]/div/div[2]/div[7]/div/div[6]/div[5]/div");
     if (flag != null)
         advert.SetAgent(true);
     return advert;
 }
Esempio n. 4
0
        public static void Test()
        {
            String phones = "";
            wClient.Proxy = null;
            wClient.Encoding = System.Text.Encoding.GetEncoding("utf-8");
            Advert advert = new Advert();

            document.LoadHtml(wClient.DownloadString(string.Format("http://irr.by/realestate/longtime/8946908/")));
            if (document.DocumentNode != null)
            {
                HtmlNode phone = document.DocumentNode.SelectSingleNode("/html/body/div[9]/div/div/div/div[4]/div/div[2]/div[6]/div/div[4]/div/div");
                HtmlNode phone1 = document.DocumentNode.SelectSingleNode("/html/body/div[9]/div/div/div/div[4]/div/div[2]/div[7]/div/div[6]/div[6]/div");
                HtmlNode phone2 = document.DocumentNode.SelectSingleNode("/html/body/div[9]/div/div/div/div[4]/div/div[2]/div[7]/div/div[6]/div[7]/div");
                HtmlNode phone3 = document.DocumentNode.SelectSingleNode("/html/body/div[9]/div/div/div/div[4]/div/div[2]/div[7]/div/div[4]/div/div");

                if (phone1 != null)
                    phones += phone1.InnerText;
                if (phone2 != null)
                    phones += phone2.InnerText;
                if (phone3 != null && phones.Equals(""))
                    phones += phone3.InnerText;
                if (phone != null && phones.Equals(""))
                    phones += phone.InnerText;
                Console.WriteLine(phones);
            }
        }