Esempio n. 1
0
        public async Task GetPricesAsync(string goodkeyword)
        {
            List <HtmlNode> goodslist = new List <HtmlNode>();
            string          searchURL = string.Format("{0}{1}?pageNumber=1", ColesOnlineURL, HttpUtility.UrlEncode(goodkeyword));

            try
            {
                CheckerHtml  htmlparse = new CheckerHtml();
                HtmlDocument html      = htmlparse.GetHTML2(searchURL);
                goodslist = html.DocumentNode.Descendants().Where(x => (x.Name == "div" && x.HasClass("product"))).ToList();
            }catch (Exception e)
            {
                return;
            }

            foreach (HtmlNode product in goodslist)
            {
                try
                {
                    string Goodrealname = product.Descendants().Where(x => (x.Name == "span" && x.HasClass("accessibility"))).ToList()[0].InnerText;
                    int    retailer     = (int)Retailer.COLES;
                    int    qty          = 1;
                    Int32.TryParse(product.Descendants().Where(x => (x.Name == "span" && x.HasClass("product-qty"))).ToList()[0].InnerText, out qty);
                    string priceString = product.Descendants().Where(x => (x.Name == "span" && x.HasClass("product-price"))).ToList()[0].InnerText;
                    float  price       = ConvertPriceString(priceString) / qty;
                    string sublink     = product.Descendants().Where(x => (x.Name == "h3" && x.HasClass("product-title"))).ToList()[0].GetAttributeValue("href", "");
                    string link        = ColesOnlineRoot + sublink;
                    string brand       = product.Descendants().Where(x => (x.Name == "span" && x.HasClass("product-brand"))).ToList()[0].InnerText;

                    GoodPrice goodprice = new GoodPrice
                    {
                        GoodRealName = Goodrealname,
                        Retailer     = retailer,
                        Price        = price,
                        Goodlink     = link,
                        Brand        = brand
                    };
                    db.GoodPrices.Add(goodprice);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                }
            }
        }
Esempio n. 2
0
        public List <Dictionary <string, float> > GetPrices(string goodkeyword)
        {
            List <Dictionary <string, float> > prices = new List <Dictionary <string, float> >();

            HttpClient http = new HttpClient();
            //var response = await http.GetByteArrayAsync(website);
            //String source = Encoding.GetEncoding("utf-8").GetString(response, 0, response.Length - 1);
            //source = WebUtility.HtmlDecode(source);
            //HtmlDocument resultat = new HtmlDocument();
            //resultat.LoadHtml(source);

            GoodInfo goodinfo = new GoodInfo
            {
                Name   = "test",
                Weight = 1.1,
                Brand  = "test"
            };

            db.GoodInfoes.Add(goodinfo);
            db.SaveChanges();
            return(prices);
        }