Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在网站中查找号码并显示_C#_Winforms - Fatal编程技术网

C# 在网站中查找号码并显示

C# 在网站中查找号码并显示,c#,winforms,C#,Winforms,我想获取“总会员”号码(在网站的右栏上),并将该号码显示在C#windows表单应用程序的标签中。以下是网站: 谢谢以下是解决您问题的解决方案: 第一步。使用System.Net.WebClient类获取此网站页面的html代码 第二步。在html代码中找到“total member”编号,并使用System.Text.RegularExpressions.Regex类获取该编号 第三步。将该编号指定给windows窗体上的标签。它表示3个单词“[HtmlDocument]”在给定上下文中无效。

我想获取“总会员”号码(在网站的右栏上),并将该号码显示在C#windows表单应用程序的标签中。以下是网站:
谢谢

以下是解决您问题的解决方案:

第一步。使用System.Net.WebClient类获取此网站页面的html代码

第二步。在html代码中找到“total member”编号,并使用System.Text.RegularExpressions.Regex类获取该编号


第三步。将该编号指定给windows窗体上的标签。

它表示3个单词“[HtmlDocument]”在给定上下文中无效。当然,这是指您的
webBrowser1.Document
。另外,数字在
SPAN
中,而不是
DIV
(我的错),因此实际的代码应该是:
HtmlElement元素=webBrowser1.Document.GetElementsByTagName(“SPAN”).OfType().FirstOrDefault(elm=>elm.GetAttribute(“className”).Equals(“ipsDataItem\u stats\u number”)。然后,数字位于
string number=element.InnerHtml中。记住设置
webBrowser1.ScriptErrorsSuppressed=true,这是一个动态页面。用正则表达式吸引新来者…喜欢它!!!(无论谁读了答案——请让你的生活更轻松,使用HTML解析器——都是更好的指导,下面的内容值得一读)。