Reputation: 878
I'm a newbie in WPF applications. I want to create a application that displays the information from a web page.. For example, my application should display the stock price of a particular company using the data in a particular site.
I want to use moneycontrol to fetch the stock price of infosys... How can I achieve this?
Upvotes: 3
Views: 4062
Reputation: 18430
There are 2 ways ways depending on the way you want to show information..
Either you can use WebControl to show the Website itself in that control,
But i think you are looking for extracting or web scraping the data from the Web Page then you can try using the HtmlAgilityPack to parse the Html and extract the required info from there
A sample code:
string tickerid = "Bse_Prc_tick";
HtmlAgilityPack.HtmlDocument doc = new HtmlWeb().Load(@"http://www.moneycontrol.com/india/stockpricequote/computers-software/infosys-technologies/IT", "GET");
if(doc != null)
{
// Fetch the stock price from the Web page
string stockprice = doc.DocumentNode.SelectSingleNode(string.Format(".//*[@id='{0}']",tickerid)).InnerText;
Console.WriteLine(stockprice);
}
Output:
2585.55
Upvotes: 6