如何在wpf应用程序中显示网页的信息
问题描述:
我是WPF应用程序的新手。我想创建一个显示网页信息的应用程序。例如,我的应用程序应该使用特定站点中的数据显示特定公司的股价。如何在wpf应用程序中显示网页的信息
我想用moneycontrol来获取infosys的股票价格......我该如何实现这一目标?
答
有2种方式取决于你想显示信息的方式方法..
要么你可以使用WebControl显示在控制网站本身,
但我认为你正在寻找解压或网站从网页报废的数据,那么你可以尝试使用HtmlAgilityPack来解析HTML,并从那里
一个示例代码提取所需的信息:
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);
}
输出:
2585.55
+1正确的答案,对于包括Codeplex上的链接 – 2012-01-14 22:04:39
@GarryVass为给予好评感谢名单... :) – 2012-01-16 06:17:30
非常感谢谢卡尔:) :) :) – Shrikey 2012-01-16 13:35:04