Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am stuck in a problem i just want to extract data from x-path attribute selector this is the div and span who's inner text want to show please help me out.
I am also performing this option in 16 times in a for each loop.

    <div class="l">
   <span id="ls_title_7596012" class="ls_h_desc" title="Required 10 marla old house in any block of bahria town">Required 10 marla old house in any block of bahria town</span>
   </div>
I am also trying this but not succeed.

What I have tried:

var name = htmlDocument?.DocumentNode?.SelectNodes("//div[@class=\"1\"]//span[@class=\"ls_h_desc\"]//title")[0].InnerText;
Posted
Updated 25-Oct-17 6:57am

The obvious problem is that the <div> you've shown has a class of l - a lower-case L - whereas you're searching for a class of 1.

You're also trying to select an element called title, which doesn't exist; the title shown is an attribute.
var name = htmlDocument?.DocumentNode?.SelectNodes("//div[@class=\"l\"]//span[@class=\"ls_h_desc\"]")[0].InnerText;
 
Share this answer
 
Comments
Jagga Lyalpuria 26-Oct-17 2:32am    
i have also try this but didn't succeed tell me any other option please and thanks
Jagga Lyalpuria 26-Oct-17 2:35am    
the compiler didn't work on it and console window is open which didn't give any response
Richard Deeming 26-Oct-17 7:34am    
What do you mean "the compiler didn't work"? It's the same code that you posted in your question, with the <div> class name corrected to match the HTML you posted, and the //title selector removed.
did you try jQuery selector?

i didn't test but something like this should work

$("div.l > span.ls_h_desc").val()
 
Share this answer
 
Comments
Jagga Lyalpuria 26-Oct-17 2:42am    
don't know how to use it in c# please send me total selector code thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900