Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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中的正则表达式从具有特定属性和值的HTML标记中提取数据#_C#_Html_Regex_Attributes_Tags - Fatal编程技术网

C# 如何使用C中的正则表达式从具有特定属性和值的HTML标记中提取数据#

C# 如何使用C中的正则表达式从具有特定属性和值的HTML标记中提取数据#,c#,html,regex,attributes,tags,C#,Html,Regex,Attributes,Tags,我一直在尝试从一些HTML数据中提取一个值,但我无法准确地关注我正在寻找的内容: 我想读的是: <span class="temp">5</span> 5 还有许多其他的“span”标记具有不同的类,所以我只需要接受“temp”类, 然后得到值 我确实没有使用正则表达式的经验,但我一直在努力解决这个问题。 以下是我试过的几句话: //MatchCollection data = Regex.Matches(searchData, @"&l

我一直在尝试从一些HTML数据中提取一个值,但我无法准确地关注我正在寻找的内容:

我想读的是:

<span class="temp">5</span>
5
还有许多其他的“span”标记具有不同的类,所以我只需要接受“temp”类, 然后得到值

我确实没有使用正则表达式的经验,但我一直在努力解决这个问题。 以下是我试过的几句话:

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">(.+?)<", RegexOptions.None);

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">\s*(.+?)\s*</span>", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp""> (.*?) </span> ", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">(([^<]|<[^\/]|<\/[^s]|<\/s[^p]|<\/sp[^a]|<\/spa[^n]|<\/span[^ \t >])*)</span>", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">\s*([^<])\s*</span>", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">\s*(<.*?>) * ([^<] *)\s*</span>", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"(?<=<span\s *class=""temp""[^><]*>\s*)[^<>]*", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"(?<=<span\s*class=""temp""[^><]*>\s*)[^<>]*", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"(?<=<span\s*class=""temp"">\s*)*", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"<span[^>] *> (.*?) </ span>", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp""></span>", RegexOptions.Singleline);

//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp""></span>", RegexOptions.Singleline); 

//MatchCollection data=Regex.Matches(searchData,@”(.+?)您可以尝试查找XPATH表达式所需的所有元素:

var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
    
// select all <span> elements with class 'temp' containing text and no element children
var xpath = "//span[contains(@class, 'temp') and text() and not(*)]";
var nodes = htmlDoc.DocumentNode.SelectNodes(xpath);

foreach (var node in nodes)
{
    Console.WriteLine(node.InnerText);
}
var htmlDoc=new HtmlDocument();
htmlDoc.LoadHtml(html);
//选择类“temp”包含文本且不包含元素子元素的所有元素
var xpath=“//span[包含(@class,'temp')和text(),而不是(*)];
var nodes=htmlDoc.DocumentNode.SelectNodes(xpath);
foreach(节点中的var节点)
{
Console.WriteLine(node.InnerText);
}

你试过这个吗?
@“[^]*”?嗨,吉尔穆蒂诺夫,很不幸,这也没用……嗨,磁控管,谢谢你,我知道了。我会找到另一种方法来提取我要找的东西。谢谢。