如何获取节点之间的文本
How to get a text between nodes
我在 nodes.It 之间提取文本时遇到问题显示了整个 span
node.I 想要获取小时值,例如 4:45;5:15 e.t.c。
var html = @"https://programtv.onet.pl/";
HtmlWeb web = new HtmlWeb();
var htmldoc=web.Load(html);
var findhours = htmldoc.DocumentNode.SelectNodes("//div[@id='boxTV1']//div[@class='hours']//span[@class='hour']");
if (findhours != null)
{
foreach (var x in findhours )
{
Console.WriteLine(x.OuterHtml);
}
}
else
{
Console.WriteLine("node = null");
}
Console.ReadLine();
Application window
您可以简单地使用 HtmlNode
对象的 InnerText
属性。检查以下 documentation.
foreach (var x in findhours )
{
Console.WriteLine(x.InnerText);
}
我在 nodes.It 之间提取文本时遇到问题显示了整个 span
node.I 想要获取小时值,例如 4:45;5:15 e.t.c。
var html = @"https://programtv.onet.pl/";
HtmlWeb web = new HtmlWeb();
var htmldoc=web.Load(html);
var findhours = htmldoc.DocumentNode.SelectNodes("//div[@id='boxTV1']//div[@class='hours']//span[@class='hour']");
if (findhours != null)
{
foreach (var x in findhours )
{
Console.WriteLine(x.OuterHtml);
}
}
else
{
Console.WriteLine("node = null");
}
Console.ReadLine();
Application window
您可以简单地使用 HtmlNode
对象的 InnerText
属性。检查以下 documentation.
foreach (var x in findhours )
{
Console.WriteLine(x.InnerText);
}