I can't get live data with c#

Viewed 63

I want to pull live data with htmlagilitypack. I need to get cryptocurrency prices instantly. I'm doing a 5 second refresh with the timer in the project but always the first value comes. For example, dolar is now 8,65try but after 15 seconds it's 8,70try. The data I get is always 8,65try the first value.

private void button1_Click(object sender, EventArgs e)
{
    timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    Uri url = new Uri("https://www.bloomberght.com/borsa");
    WebClient client = new WebClient();
    client.Encoding = System.Text.Encoding.UTF8;
    string html = client.DownloadString(url);
    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
    document.LoadHtml(html);
    HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//a[@id='dolar']/span[@class='data-info']/small[@data-type='son_fiyat']");

    foreach (var item in nodes)
    {
        string link = item.Attributes["class"].Value;
        label1.Text = item.InnerText;
        listBox1.Items.Add(item.InnerText);
    }
}
1 Answers

You may be hitting cache.

Try to specify BypassCache level for your request:

client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
Related