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.
This might do the trick for you
doc.DocumentNode.SelectSingleNode("//head/title");
or
doc.DocumentNode.SelectSingleNode("//title");
or
doc.DocumentNode.Descendants("title").FirstOrDefault()
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(htmlContent);
var result = doc.DocumentNode.SelectNodes("title").FirstOrDefault();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With