I have this structure
<span class="glyphicon glyphicon-user"></span>
123 <br>
I want to get "123"
this code get between the tag if exist
var username = document.DocumentNode.SelectSingleNode("//p[@class='glyphicon-user']");
//Response.Write(username.InnerText);
but i want to get "123"
This is one possible way, based solely on the HTML sinppet posted so far :
var query = "//span[@class='glyphicon glyphicon-user']/following-sibling::text()[1]";
var username = document.DocumentNode.SelectSingleNode(query);
Console.WriteLine(username.InnerText.Trim());
Basically the XPath looks for span
with certain class
attribute value, and then return the nearest text node located after the span
. There might be a better way depending on your exact need and the actual HTML structure.
output :
123