示例#1
0
        private async Task LoadImg(BarCodeOut bar)
        {
            string CodeWares = bar.CodeWares.ToString();

            try
            {
                var        url       = bar.UrlPicture;
                HttpClient client    = new HttpClient();
                WebClient  webClient = new WebClient();

                string ex = "jpg";
                webClient.DownloadFile(url, $"d:\\pictures\\highPhoto\\{CodeWares.Trim()}.{ex}");
                Console.WriteLine("Ok");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#2
0
        public async Task <BarCodeOut> GetInfoRozetka(BarCodeOut pBCO)
        {
            string CodeWares = pBCO.CodeWares.ToString();

            pBCO.Site = "Rozetka";
            //var pBCO = new BarCodeOut() { BarCode = parBarCode, Error = "Ok", DateUrl = DateTime.Now ,Site="Rozetka"};
            if (string.IsNullOrEmpty(CodeWares))
            {
                CodeWares = pBCO.BarCode;
            }
            try
            {
                var        url       = $"https://search.rozetka.com.ua/ua/search/api/v6/autocomplete/?front-type=xl&country=UA&lang=ua&text={pBCO.BarCode}";
                HttpClient client    = new HttpClient();
                WebClient  webClient = new WebClient();
                // Add a new Request Message
                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
                //requestMessage.Headers.Add("Accept", "application/vnd.github.v3+json");
                // Add our custom headers
                //requestMessage.Content = new StringContent("", Encoding.UTF8, "application/json");
                var response = await client.SendAsync(requestMessage);

                if (response.IsSuccessStatusCode)
                {
                    var res = await response.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(res))
                    {
                        var i = res.IndexOf("goods");////"<section class=\"site-content\">"
                        var j = 0;
                        if (i > 0)
                        {
                            i = res.IndexOf("image");
                            if (i > 0)
                            {
                                var res1 = res.Substring(i + 8, 300);
                                var ex   = "jpg";
                                i = res1.IndexOf(".jpg");
                                j = res1.IndexOf(".png");
                                if (j > 0 && i <= 0)
                                {
                                    i  = j;
                                    ex = "png";
                                }
                                if (i > 0)
                                {
                                    res1 = res1.Substring(0, i + 4);
                                    pBCO.UrlPictureRozetka = res1;
                                    webClient.DownloadFile(res1, $"d:\\pictures\\rozetkaImg\\{CodeWares.Trim()}.{ex}");
                                    pBCO.Error = "Ok";
                                }
                            }
                            i = res.IndexOf("href");
                            var r = res.Substring(i + 7);
                            i              = r.IndexOf("\"");
                            r              = r.Substring(0, i);
                            url            = r + "characteristics/";
                            pBCO.Url       = url;
                            requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
                            response       = await client.SendAsync(requestMessage);

                            if (response.IsSuccessStatusCode)
                            {
                                res = await response.Content.ReadAsStringAsync();

                                i = res.IndexOf("<product-tab-characteristics");
                                if (i > 0)
                                {
                                    res = res.Substring(i);
                                }
                                i = res.IndexOf("</product-tab-characteristics>");
                                if (i > 0)
                                {
                                    res = res.Substring(0, i);
                                }
                                pBCO.Data = res;
                                if (res.IndexOf("<span>Вага</span>") > 0)
                                {
                                    var    str = GetElement(res, "<span>Вага</span>");
                                    string t   = GetElement(str, "<span class=\"ng-star-inserted\"", ">", "</span>");
                                    pBCO.WeightUrl = ToDecimal(t.Substring(0, t.Length - 3));
                                }
                            }
                        }
                        else
                        {
                            pBCO.Error = "Product Not Found";
                        }
                    }
                }
                else
                {
                    pBCO.Error = "Bad Request";
                }
            }
            catch (Exception ex)
            {
                pBCO.Error = ex.Message;
                // return false;
            }
            pBCO.DateUrl = DateTime.Now;
            return(pBCO);
        }
示例#3
0
        public async Task <BarCodeOut> GetInfoListex(string parBarCode = "4823000916524", string pArticle = "")
        {
            var Res = new BarCodeOut()
            {
                BarCode = parBarCode, Error = "Ok", DateUrl = DateTime.Now
            };

            if (string.IsNullOrEmpty(pArticle))
            {
                pArticle = parBarCode;
            }
            try
            {
                var        url       = $"https://listex.info/search/?q={parBarCode}&type=goods";
                HttpClient client    = new HttpClient();
                WebClient  webClient = new WebClient();
                // Add a new Request Message
                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
                //requestMessage.Headers.Add("Accept", "application/vnd.github.v3+json");
                // Add our custom headers
                //requestMessage.Content = new StringContent("", Encoding.UTF8, "application/json");
                var response = await client.SendAsync(requestMessage);

                if (response.IsSuccessStatusCode)
                {
                    var res = await response.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(res))
                    {
                        var i = res.IndexOf("<a href=\"/product/");////"<section class=\"site-content\">"
                        var j = 0;
                        if (i > 0)
                        {
                            var r = res.Substring(i + 9);
                            i              = r.IndexOf("\"");
                            r              = r.Substring(0, i);
                            url            = "https://listex.info/uk" + r;
                            Res.Url        = url;
                            requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
                            response       = await client.SendAsync(requestMessage);

                            if (response.IsSuccessStatusCode)
                            {// "<p class=\"product-specifications-title\"" "panel panel-transparent product-info-tab"
                                res = await response.Content.ReadAsStringAsync();

                                /* i = res.IndexOf("src=\"https://icf.listex.info/300x200/");
                                 * if (i > 0)
                                 * {
                                 *   var res1 = res.Substring(i + 5, 300);
                                 *   var ex = "jpg";
                                 *   i = res1.IndexOf(".jpg");
                                 *   j = res1.IndexOf(".png");
                                 *   if (j > 0 && i <= 0)
                                 *   {
                                 *       i = j;
                                 *       ex = "png";
                                 *   }
                                 *   if (i > 0)
                                 *   {
                                 *       res1 = res1.Substring(0, i + 4);
                                 *       Res.UrlPicture = res1;
                                 *       webClient.DownloadFile(res1, $"d:\\pictures\\{pArticle.Trim()}.{ex}");
                                 *   }
                                 * }*/

                                i = res.IndexOf("<section class=\"site-content\">");//("<p class=\"product-specifications-title\"");
                                if (i > 0)
                                {
                                    res = res.Substring(i);
                                }
                                i = res.IndexOf("<footer class=\"site-footer\">");//"panel panel-transparent product-info-tab");//
                                if (i > 0)
                                {
                                    res = res.Substring(0, i);
                                }

                                res = Regex.Replace(res, "[ ]+", " ");
                                res = Regex.Replace(res, "[\t]+", "\t");

                                Res.Data = res;

                                var s = GetElement(res, "Вагогабаритні характеристики");
                                if (!string.IsNullOrEmpty(s))
                                {
                                    r = GetElement(s, "Вага брутто, кг", "<td>", "</td>");

                                    Res.WeightUrl = Decimal.Parse(r, CultureInfo.InvariantCulture); // .Replace('.', ','));
                                }
                            }
                            else
                            {
                                Res.Error = "Bad Request Product";
                            }
                        }
                        else
                        {
                            Res.Error = "Product Not Found";
                        }
                    }
                }
                else
                {
                    Res.Error = "Bad Request";
                }
            }
            catch (Exception ex)
            {
                Res.Error = ex.Message;
                // return false;
            }
            return(Res);
        }