jason
jason

Reputation: 7164

How to get title tag using HTML Agility Pack

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.

Upvotes: 10

Views: 8464

Answers (1)

Mohit S
Mohit S

Reputation: 14044

This might do the trick for you

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

or

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

or

doc.DocumentNode.Descendants("title").FirstOrDefault()

Upvotes: 19

Related Questions