Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 201
jason Avatar asked Nov 29 '16 07:11

jason


2 Answers

This might do the trick for you

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

or

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

or

doc.DocumentNode.Descendants("title").FirstOrDefault()
like image 130
Mohit S Avatar answered Nov 12 '22 01:11

Mohit S


HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(htmlContent);

var result = doc.DocumentNode.SelectNodes("title").FirstOrDefault();
like image 1
mybirthname Avatar answered Nov 12 '22 01:11

mybirthname