0

I want to get an element by class name with html agility pack.the element is inside a lot of other elements, so i can't get element like:

//section[@class='class1']/div[@class='class2']/div[@class='class3']/

I Want to get my element <p class="title">My Text</p> directly.

I get the body of html document with the following code:

var body = htmlDoc.DocumentNode.SelectSingleNode("//body");

1 Answers1

-1

Simply, try this code:

HtmlNode myParagraph = htmlDoc.DocumentNode.SelectSingleNode("//p[@class='title']");

I hope this helps you.

Ehsan Mohammadi
  • 1,168
  • 1
  • 15
  • 21