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; }
// 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; }