Пример #1
0
        static async Task <CoinsRates> parseCoin(string xpath, string acronim)
        {
            var site = @"https://9999d.ru/";

            HtmlWeb web = new HtmlWeb();

            var htmlDoc = await web.LoadFromWebAsync(site);

            var selector = "//div[@class='catalog item-views table catalog_table_2' and @data-slice='Y']";

            var node = htmlDoc.DocumentNode.SelectSingleNode(selector);


            var htmlDoc2 = new HtmlDocument();

            htmlDoc2.LoadHtml("<div>" + node.InnerHtml + "</div>");

            var nodeCoin = htmlDoc2.DocumentNode.SelectSingleNode(xpath);

            var innerText = Regex.Replace(nodeCoin.InnerText, @"\s+", " ");

            var prices = GetBetweenTwoWords("ПРОДАЖА", "Цена за грамм", innerText);

            var pricePair = prices.Split(new string[1] {
                "ПОКУПКА"
            }, StringSplitOptions.RemoveEmptyEntries);

            pricePair = pricePair.Select(x => x.Replace("₽", "")).ToArray();

            CoinsRates coin = new CoinsRates()
            {
                Date    = DateTime.Now,
                Site    = site,
                Acronim = acronim
            };

            coin.Sell = double.Parse(pricePair[0]);
            coin.Buy  = double.Parse(pricePair[1]);

            return(coin);
        }
Пример #2
0
        static async Task <CoinsRates> getRshbRuCoin(string xpath, string acronim)
        {
            var site = @"https://www.rshb.ru/natural/coins/";

            HtmlWeb web = new HtmlWeb();

            var htmlDoc = web.Load(site);

            var idLink = htmlDoc.DocumentNode.SelectSingleNode(xpath);

            var coinNode = idLink.ParentNode.ParentNode.ParentNode;

            var coinHtmlDoc = new HtmlDocument();

            coinHtmlDoc.LoadHtml("<div>" + coinNode.InnerHtml + "</div>");


            string buySelect  = "//span[@class='b-coins-items-item-cost-b']";
            string sellSelect = "//div[@class='b-coins-items-item-quotes-price  ']";

            string buyPrice  = coinHtmlDoc.DocumentNode.SelectSingleNode(buySelect).InnerText.Replace("Р", "");
            string sellPrice = coinHtmlDoc.DocumentNode.SelectSingleNode(sellSelect).InnerText.Replace("Р", "");


            CoinsRates coin = new CoinsRates()
            {
                Acronim = acronim,
                Date    = DateTime.Now,
                Site    = site
            };

            coin.Buy  = double.Parse(buyPrice);
            coin.Sell = double.Parse(sellPrice);

            return(coin);
        }
Пример #3
0
        static async Task <CoinsRates> getCoinRateRicgoldCom(string url, string acronim)
        {
            string loadedHtml = await loadHtml(url);

            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(loadedHtml);

            string xpath = "//div[@class='bull_price']";

            var node = htmlDoc.DocumentNode.SelectSingleNode(xpath);

            var nodeText = node.InnerText;

            var prices = Regex.Replace(nodeText, @"[^0-9,:]+", "", RegexOptions.ECMAScript);

            var priceList = prices.Split(':').ToArray();

            int whiteCount = 0;

            foreach (var str in priceList)
            {
                if (str == "")
                {
                    ++whiteCount;
                }
            }

            CoinsRates coin = new CoinsRates()
            {
                Acronim = acronim,
                Date    = DateTime.Now,
                Site    = url
            };

            if (whiteCount > 1)
            {
                if (priceList[1] != "")
                {
                    coin.Sell = double.Parse(priceList[1]);
                }
                else
                {
                    coin.Sell = 0;
                }
                if (priceList[2] != "")
                {
                    coin.Buy = double.Parse(priceList[2]);
                }
                else
                {
                    coin.Buy = 0;
                }
            }
            else
            {
                coin.Sell = double.Parse(priceList[1]);
                coin.Buy  = double.Parse(priceList[2]);
            }

            return(coin);
        }