Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to scrap some webpages.
for that html code
is
<span>
<p class="sc-fzplWN jNTWvK">28/04/1998</p>
</span>

I want to extract the date 28/04/1998.

Unfortunately I am getting null value.

Please suggest me correct xpath or any mistake if i have made.

What I have tried:

HtmlWeb web = new HtmlWeb();
                HtmlDocument doc = new HtmlDocument();
               
                doc = web.Load("https://www.tmdn.org/tmview/#/tmview/results?page=1&pageSize=100&criteria=C&adFrom=1000-03-01&adTo=2022-01-13");
                HtmlNode[] nodes = (doc.DocumentNode.SelectNodes("/span//p[@class='sc-fzplWN jNTWvK']/p")).ToArray();               




                foreach (var node in nodes)
                {
                    if (node != null)
                    {
                        Console.WriteLine(node.InnerHtml);
                    }
                }
Posted
Updated 27-Jun-22 2:08am
v4
Comments
Richard MacCutchan 27-Jun-22 8:06am    
You need to check the exact content of the web page. It may be that the node selector you are using is wrong.

1 solution

According to SelectNodes Method in Html Agility Pack (HAP)[^] I think the selection criteria should begin with // to indicate it's a global search. I think if the selector begins with just / it reads that as "from the root element"?

Also the selection criteria seems to be selecting the p element twice?
p[@class='sc-fzplWN jNTWvK']/p
^                            ^
1                            2

It looks like you only need to select it once so your final query selector should probably just be:
"//p[@class='sc-fzplWN jNTWvK']"

Which means "find me, anywhere in the document (because of //) any <p> elements with this class"
 
Share this answer
 
v2

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