9

I'm parsing an HTML file using HTML Agility Pack. I want to get

<title>Some title <title>

As you see, title doesn't have a class. So I couldn't catch it no matter what I have tried. I couldn't find the solution on the web either. How can I catch this HTML tag which doesn't have a class? Thanks.

1

2 Answers 2

16

This might do the trick for you

doc.DocumentNode.SelectSingleNode("//head/title");

or

doc.DocumentNode.SelectSingleNode("//title");

or

doc.DocumentNode.Descendants("title").FirstOrDefault()
0
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(htmlContent);

var result = doc.DocumentNode.SelectNodes("title").FirstOrDefault();
1
  • This does not work as title is not a direct child of the document node. See the other answer. Mar 15 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.