コード例 #1
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;
        }
コード例 #2
0
ファイル: ParseHelperIRR.cs プロジェクト: alnasfire/irr
 // 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;
 }