Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to scrape price value out of the nse reliance website. I use htmlagilitypack. Unfortunately I am getting null value for HtmlNode even though value is present in the webpage.

What I have tried:

namespace stockmarket_data
{ 
using HtmlAgilityPack;
    using System;
    using System.Linq;

    internal class Program
{
        static void Main(string[] args)
        {
            string url = "https://www.google.com/search?q=nse+reliance&oq=nse+reliance&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBCTc2NzRqMGoxNagCALACAA&sourceid=chrome&ie=UTF-8";

            var web = new HtmlWeb();
            var doc = web.Load(url);
            try
            {
                HtmlNode priceElements = doc.DocumentNode.SelectSingleNode("//span[@class='knowledge-finance-wholepage-chart__hover-card-value']");

                if (priceElements != null)
                {
                    Console.WriteLine(priceElements.InnerHtml.ToString());
                }
            }
            catch (Exception ex)
            {
                    
                    Console.WriteLine(ex.Message.ToString());

            }
           
    }               
    }
}
Posted
Updated 16-Dec-23 19:31pm
v2
Comments
Richard MacCutchan 17-Dec-23 3:25am    
You are using the results of a Google search, so that data may well not be in the results.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900