views:

146

answers:

2

Hi All, From here, I am trying to get data from stock quote for every 10 mins interval.

I used WebClient for downloading the page content and for parsing I used regular expressions. It is working fine for other urls. For the Particular URL, my parsing code not working.

I think it is the problem with javascript, When I load the page in Browser, after loading the page content, It took some extra time to plot the data. May be this guy is using some client side script for this page. Can anyone help me Please..........

+3  A: 

HTML Agility Pack will save you tons of headaches. Try it instead of using regexps to parse HTML.

For what it's worth, in the page you link to the quote data is indeed in Javascript code, check http://www.nseindia.com/js/getquotedata.js and http://www.nseindia.com/js/quote_data.js

Vinko Vrsalovic
+1 Agreed, and of course the obligatory link: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
Nick Craver
Hi Vinko, I will follow your suggestion. Thanks for your help......
Raghavendra
Hello Vinko, one more doubt, I have downloaded the content of the link to String as like @Asad Butt suggests, When I see the source of this String there is no values(Open Interest) in it. I think those are dynamically generates this report using JavaScript, Is this situation can handle by the HTML Agility Pack?
Raghavendra
@Raghavendra: No, you have to understand how the data is stored in the Javascript file, download it and obtain the relevant part.
Vinko Vrsalovic
@Vinko, I have gone through the javascript file and I found there is a Iframe and I got the exact link. From the above page, in middle part it contains a seperate URL to load data and I found it. Once again Thank you very much.......
Raghavendra
+1  A: 

as per @Vinko Vrsalovic answer, Html Agility pack is your friend. Here is a sample

  WebClient client = new WebClient();
  string source = client.DownloadString(url);

  HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
  document.LoadHtml(source);

  HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//*[@href]");

   foreach (HtmlNode node in nodes)
   {
    if (node.Attributes.Contains("class"))
    {
     if (node.Attributes["class"].Value.Contains("StockData"))
     {// Here is our info }
    }
   }
Asad Butt