gpt4 book ai didi

c# - 如何在wpf应用程序中显示网页的信息

转载 作者:行者123 更新时间:2023-11-30 14:37:48 32 4
gpt4 key购买 nike

我是 WPF 应用程序的新手。我想创建一个显示网页信息的应用程序。例如,我的应用程序应该使用特定站点中的数据显示特定公司的股票价格。

我想使用 moneycontrol获取 infosys 的股票价格...我该如何实现?

最佳答案

根据您想要显示信息的方式,有两种方式..

您可以使用 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

关于c# - 如何在wpf应用程序中显示网页的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8862517/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com