Advertisement
kej

Untitled

kej
May 25th, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Net.Http;
  4. using System.Threading.Tasks;
  5. using HtmlAgilityPack;
  6.  
  7. namespace XMLParser
  8. {
  9. class Program
  10. {
  11. static async Task Main(string[] args)
  12. {
  13. double usdPrice, eurPrice;
  14. var url = @"https://www.cbr-xml-daily.ru/daily.xml";
  15. var rawHtml = await new HttpClient().GetStringAsync(url);
  16. var doc = new HtmlDocument();
  17. doc.LoadHtml(rawHtml);
  18. var valutes = doc.DocumentNode.ChildNodes["ValCurs"].ChildNodes;
  19. foreach (var valute in valutes)
  20. {
  21. var charCode = valute.ChildNodes["CharCode"].InnerText;
  22. var price = valute.ChildNodes["Value"].InnerText;
  23. if (charCode == "USD")
  24. {
  25. usdPrice = double.Parse(price);
  26. Console.WriteLine($"1 {charCode} = {usdPrice}");
  27. }
  28. else if (charCode == "EUR")
  29. {
  30. eurPrice = double.Parse(price);
  31. Console.WriteLine($"1 {charCode} = {eurPrice}");
  32. }
  33. }
  34. ;
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement