Example #1
0
        public string GetPageURL(string htmlBody)
        {
            ////div[@id=\"a1d1container\"]

            var products = new List <Product>();
            var doc      = new HtmlDocument();

            doc.LoadHtml(htmlBody);
            HtmlNode root = doc.DocumentNode;

            //Get all pages as quikr's search is not so great
            var adNode = root.SelectSingleNode("//*[@id=\"a1d1container\"]");

            var adNodes = adNode.SelectNodes("//div[@class=\"snb_entire_ad ad \"]");

            foreach (var node in adNodes)
            {
                //*[@id="ad210808315"]/div[1]/div[2]/div[1]/h3/a
                //*[@id="ad214637183"]/div[1]/div[2]/div[1]/h3/a
                //a[@class='adttllnk unbold']
                //div[1] / div[2] / div[1] / h3 / a
                var ad    = node.SelectSingleNode("//h3[@class='adtitlesnb translate']");
                var title = ad.InnerText;

                if (title.ToUpper().Contains("PS4") || title.ToUpper().Contains("PLAYSTATION") || title.ToUpper().Contains("PLAY STATION") || title.ToUpper().Contains("SONY"))
                {
                    var urlNode   = ad.SelectSingleNode("a");
                    var gameTitle = urlNode.Attributes["title"].Value.Trim();

                    var url = urlNode.Attributes["href"].Value;

                    products.Add(new Product()
                    {
                        RetailName = gameTitle,
                        Url        = url
                    });
                }
            }

            var bestProduct = NameMatching.BestProduct(products, ProductName, 0.8);

            return(bestProduct != null? bestProduct.Url : string.Empty);
        }
Example #2
0
        public string GetPageURL(string htmlBody)
        {
            //*[@id="675441"]/div/div[5]/div[1]/div/div[1]/div/a[1]
            var products = new List <Product>();
            var doc      = new HtmlDocument();

            doc.LoadHtml(htmlBody);
            HtmlNode root = doc.DocumentNode;

            //var nodes = root.SelectNodes("//*[@id=\"content_wrapper\"]/div[3]/div[2]")[0].SelectNodes("//div[@class=\"product-title\"]");
            //Get all pages as quikr's search is not so great
            //var adNode = root.SelectSingleNode("//*[@id=\"offer onclick\"]");
            //*[@id="offers_table"]/tbody/tr[2]/td/table/tbody/tr[1]/td[2]/h3/a
            //*[@id="offers_table"]/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/h3/a
            // table/tbody/tr[1]/td[2]/h3/a
            var adNodes = root.SelectNodes("//td[@class=\"offer onclick  \"]");

            foreach (var node in adNodes)
            {
                var title = node.InnerText.Trim();

                if (title.ToUpper().Contains("PS4") || title.ToUpper().Contains("PLAYSTATION") || title.ToUpper().Contains("PLAY STATION") || title.ToUpper().Contains("SONY"))
                {
                    var urlNode   = node.SelectSingleNode("//table/tbody/tr[1]/td[2]/h3/a");
                    var gameTitle = urlNode.ChildNodes["span"].InnerText.Trim();

                    var url = urlNode.Attributes["href"].Value;

                    products.Add(new Product()
                    {
                        RetailName = gameTitle,
                        Url        = url
                    });
                }
            }

            var bestProduct = NameMatching.BestProduct(products, ProductName, 0.8);

            return(bestProduct != null? bestProduct.Url : string.Empty);
        }
Example #3
0
        public string GetPageURL(string htmlBody)
        {
            //*[@id="675441"]/div/div[5]/div[1]/div/div[1]/div/a[1]
            var products = new List <Product>();
            var doc      = new HtmlDocument();

            doc.LoadHtml(htmlBody);
            HtmlNode root = doc.DocumentNode;

            //Get all pages as SnapDeal's search is not so great
            //var nodes = root.SelectNodes("//*[@id=\"content_wrapper\"]/div[3]/div[2]")[0].SelectNodes("//div[@class=\"product-title\"]");
            var nodes = root.SelectNodes("//div[@class=\"hoverProductWrapper product-txtWrapper  \"]");

            foreach (var node in nodes)
            {
                var title = node.SelectSingleNode("div[1]").InnerText.Trim();

                if (title.ToUpper().Contains("PS4") || title.ToUpper().Contains("PLAYSTATION") || title.ToUpper().Contains("PLAY STATION") || title.ToUpper().Contains("SONY"))
                {
                    var urlNode   = node.SelectSingleNode("div[1]").ChildNodes["a"];
                    var gameTitle = urlNode.InnerText.Trim();

                    var url   = urlNode.Attributes["href"].Value;
                    var price = Convert.ToInt32((node.SelectSingleNode("a/div[2]/div/span")).InnerHtml.Replace("Rs", "").Trim());

                    products.Add(new Product()
                    {
                        RetailName = gameTitle,
                        Url        = url,
                        Price      = price
                    });
                }
            }

            var bestProduct = NameMatching.BestProduct(products, ProductName, 0.8, this);

            return(bestProduct != null? bestProduct.Url : string.Empty);
        }