public static void Main(string[] args)
HtmlDocument htmlDoc = new HtmlDocument();
string url = "https://www.w3schools.com/html/html_elements.asp";
string urlResponse = URLRequest(url);
htmlDoc.LoadHtml(urlResponse);
var titleNodes = htmlDoc.DocumentNode.SelectNodes("//title");
Console.WriteLine("The title of the page is:");
Console.WriteLine(titleNodes.FirstOrDefault().InnerText);
var keywwordNodes = htmlDoc.DocumentNode.SelectNodes("//meta[translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'keywords']");
if(keywwordNodes != null)
foreach(var keywordNode in keywwordNodes)
string content = keywordNode.GetAttributeValue("content", "");
if (!String.IsNullOrEmpty(content))
string[] keywords = content.Split(new string[] { "," }, StringSplitOptions.None);
Console.WriteLine("Here are the keywords:");
Console.WriteLine(String.Format("{0}", content));
foreach(var keyword in keywords)
Console.WriteLine(String.Format("\t- {0}", keyword));
var anchorNodes = htmlDoc.DocumentNode.SelectNodes("//a");
Console.WriteLine(String.Format("We found {0} anchor tags on this page. Here is the text from those tags:", anchorNodes.Count));
foreach (var anchorNode in anchorNodes)
Console.WriteLine(String.Format("{0} - {1}", anchorNode.InnerText, anchorNode.GetAttributeValue("href", "")));
static string URLRequest(string url)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)";
string responseContent = null;
using (WebResponse response = request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader streamreader = new StreamReader(stream))
responseContent = streamreader.ReadToEnd();
return (responseContent);