예제 #1
0
        private async Task <bool> Search(string url, string manufacturer, string model, bool strictSearch)
        {
            try
            {
                CultureInfo culture  = new CultureInfo("fr-FR", false);
                var         response = await m_refScraper.Analyze(new Uri(url));

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var html = await response.Content.ReadAsStringAsync();

                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

                    doc.LoadHtml(html);
                    var root         = doc.DocumentNode;
                    var productNodes = root.CssSelect("li.ajax_block_product");
                    foreach (var node in productNodes)
                    {
                        string m     = string.Empty;
                        string price = string.Empty;
                        string murl  = string.Empty;
                        string brand = string.Empty;
                        foreach (HtmlNode modelNode in node.CssSelect("a.product-name"))
                        {
                            m = modelNode.GetAttributeValue("title");
                            WebScraper.ExtractBrandFromModel(manufacturer, ref m, ref brand);
                        }
                        foreach (HtmlNode hrefNode in node.CssSelect("a.quick-view"))
                        {
                            murl = hrefNode.GetAttributeValue("href");
                        }
                        foreach (HtmlNode priceNode in node.CssSelect("span.product-price"))
                        {
                            price = priceNode.InnerHtml;
                            price = price.Trim().Replace("\u202F", "").Replace(",", ".");
                            price = price.Replace(".00", "");
                        }

                        bool canAdd = culture.CompareInfo.IndexOf(m, model, CompareOptions.IgnoreCase) >= 0;
                        if (strictSearch)
                        {
                            canAdd &= culture.CompareInfo.IndexOf(brand, manufacturer, CompareOptions.IgnoreCase) >= 0;
                        }
                        if (canAdd)
                        {
                            m_refScraper.AddPrice(brand, m, ShopName, murl, price);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_refScraper.ThrowException(ShopName, ex.Message);
            }

            return(true);
        }
예제 #2
0
        private async Task <bool> Search(string url, string manufacturer, string model, bool strictSearch)
        {
            CultureInfo culture  = new CultureInfo("fr-FR", false);
            var         response = await m_refScraper.Analyze(new Uri(url));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var html = await response.Content.ReadAsStringAsync();

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

                doc.LoadHtml(html);
                var root         = doc.DocumentNode;
                var productNodes = root.CssSelect("div.product");
                foreach (var productNode in productNodes)
                {
                    string m     = string.Empty;
                    string price = string.Empty;
                    string murl  = string.Empty;
                    string brand = string.Empty;
                    foreach (HtmlNode urlNode in productNode.CssSelect("a.product-link"))
                    {
                        murl = "https://www.keymusic.com" + urlNode.GetAttributeValue("href");
                    }
                    foreach (HtmlNode nameNode in productNode.CssSelect("div.title"))
                    {
                        m = WebScraper.UppercaseFirst(nameNode.InnerText.Trim());
                        WebScraper.ExtractBrandFromModel(manufacturer, ref m, ref brand);
                    }
                    foreach (HtmlNode priceNode in productNode.CssSelect("span.price-label"))
                    {
                        price  = HttpUtility.HtmlDecode(priceNode.InnerHtml).Trim();
                        price  = price.Replace(",", ".");
                        price += " €";
                    }
                    bool canAdd = culture.CompareInfo.IndexOf(m, model, CompareOptions.IgnoreCase) >= 0;
                    if (strictSearch)
                    {
                        canAdd &= culture.CompareInfo.IndexOf(brand, manufacturer, CompareOptions.IgnoreCase) >= 0;
                    }
                    if (canAdd)
                    {
                        m_refScraper.AddPrice(brand, m, ShopName, murl, price);
                    }
                }
            }
            else
            {
                m_refScraper.ThrowException(ShopName, response.ReasonPhrase);
            }

            return(true);
        }
예제 #3
0
        private async Task <bool> Search(string url, string manufacturer, string model, bool strictSearch)
        {
            CultureInfo culture = new CultureInfo("fr-FR", false);

            var response = await m_refScraper.Analyze(new Uri(url));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var html = await response.Content.ReadAsStringAsync();

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);

                var root        = doc.DocumentNode;
                var productNode = root.CssSelect(".product-box");
                foreach (var node in productNode)
                {
                    string enc         = node.GetAttributeValue("data-product");
                    string info        = HttpUtility.HtmlDecode(enc);
                    var    productInfo = JsonConvert.DeserializeObject <dynamic>(info);
                    string brand       = productInfo.brand;
                    string murl        = url;
                    string m           = productInfo.name;
                    string price       = productInfo.price;
                    price = price.Replace(".00", "");
                    string currency = CurrencyTools.GetCurrencySymbol((string)productInfo.currencyCode);

                    WebScraper.ExtractBrandFromModel(manufacturer, ref m, ref brand);

                    foreach (HtmlNode urlNode in node.CssSelect("div.product-thumb > a"))
                    {
                        murl = "https://www.bax-shop.fr" + urlNode.GetAttributeValue("href");
                    }

                    bool canAdd = culture.CompareInfo.IndexOf(m, model, CompareOptions.IgnoreCase) >= 0;
                    if (strictSearch)
                    {
                        canAdd &= culture.CompareInfo.IndexOf(brand, manufacturer, CompareOptions.IgnoreCase) >= 0;
                    }
                    if (canAdd)
                    {
                        m_refScraper.AddPrice(brand, m, ShopName, murl, price + " " + currency);
                    }
                }
            }
            else
            {
                m_refScraper.ThrowException(ShopName, response.ReasonPhrase);
            }

            return(true);
        }
예제 #4
0
        private async Task <bool> Search(string url, string manufacturer, string model, bool strictSearch)
        {
            CultureInfo culture  = new CultureInfo("fr-FR", false);
            var         response = await m_refScraper.Analyze(new Uri(url));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var html = await response.Content.ReadAsStringAsync();

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

                doc.LoadHtml(html);
                var root         = doc.DocumentNode;
                var productNodes = root.CssSelect("div.tile-product");
                foreach (var productNode in productNodes)
                {
                    string m     = string.Empty;
                    string price = string.Empty;
                    string murl  = string.Empty;
                    string brand = string.Empty;
                    foreach (HtmlNode urlNode in productNode.CssSelect("a.kor-product-link"))
                    {
                        murl = urlNode.GetAttributeValue("href");
                        m    = urlNode.InnerText.Trim();
                        WebScraper.ExtractBrandFromModel(manufacturer, ref m, ref brand);
                    }
                    foreach (HtmlNode priceNode in productNode.CssSelect("span.kor-product-sale-price-value"))
                    {
                        price = HttpUtility.HtmlDecode(priceNode.InnerHtml).Trim();
                        price = price.Replace(",00", "");
                        price = price.Replace(".", "");
                        price = price.Replace(",", ".");
                    }
                    bool canAdd = culture.CompareInfo.IndexOf(m, model, CompareOptions.IgnoreCase) >= 0;
                    if (strictSearch)
                    {
                        canAdd &= culture.CompareInfo.IndexOf(brand, manufacturer, CompareOptions.IgnoreCase) >= 0;
                    }
                    if (canAdd)
                    {
                        m_refScraper.AddPrice(brand, m, "Music Store", murl, price);
                    }
                }
                if (productNodes.Count() == 0)
                {
                    productNodes = root.CssSelect("div.productdata");
                    if (productNodes.Count() == 1)
                    {
                        // Direct to product page
                        string m       = string.Empty;
                        string price   = string.Empty;
                        string murl    = string.Empty;
                        string brand   = string.Empty;
                        var    urlNode = root.CssSelect("input#RedirectURL");
                        if (urlNode.Count() == 1)
                        {
                            murl = urlNode.First().GetAttributeValue("value");
                        }
                        foreach (HtmlNode dataNode in productNodes.CssSelect("h1"))
                        {
                            brand = dataNode.ChildNodes.First().InnerText;
                            m     = dataNode.ChildNodes.Last().InnerText;
                        }

                        foreach (HtmlNode priceNode in productNodes.CssSelect("span.kor-product-sale-price-value"))
                        {
                            price = HttpUtility.HtmlDecode(priceNode.InnerHtml).Trim();
                            price = price.Replace(",00", "");
                            price = price.Replace(".", "");
                            price = price.Replace(",", ".");
                        }
                        bool canAdd = culture.CompareInfo.IndexOf(m, model, CompareOptions.IgnoreCase) >= 0;
                        if (strictSearch)
                        {
                            canAdd &= culture.CompareInfo.IndexOf(brand, manufacturer, CompareOptions.IgnoreCase) >= 0;
                        }
                        if (canAdd)
                        {
                            m_refScraper.AddPrice(brand, m, ShopName, murl, price);
                        }
                    }
                }
            }
            else
            {
                m_refScraper.ThrowException(ShopName, response.ReasonPhrase);
            }

            return(true);
        }