Over a million developers have joined DZone.

How to Extract a URL’s Title, Description and Images using HTML Agility Utility

DZone's Guide to

How to Extract a URL’s Title, Description and Images using HTML Agility Utility

Free Resource

Extracting the details from any web page URL is not so easy task. Because you need something to track that page. In this article we are going to extract the details like Title, Description and collection of Images. To do this we need HTML Agility Utility in our web application. When we share a link on Facebook or Google+ we see that the Image and description comes automatically after few seconds. Exactly they have coding to perform this. As we will proceed in this article we will learn step by step to do this. I am attaching a link to download the HTML Agility Utility and also the demo project that you can download on your PC for reference.

Let me know if you getting any problem with this example. To get HTML Agility Utility you can download here. To Download the Demo of this example download here.

HtmlAgilityPack.1.4.6 Demo imageconvert

* Namespaces that are Required:

using System.Net;
using System.IO;
using System.Data;
using HtmlAgilityPack;

* Coding to get the Title, Description and Images:

protected void btnGet_Click(object sender, EventArgs e)
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(txturl.Text));
request.Method = WebRequestMethods.Http.Get;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

StreamReader reader = new StreamReader(response.GetResponseStream());

String responseString = reader.ReadToEnd();


HtmlDocument doc = new HtmlDocument();

String title = (from x in doc.DocumentNode.Descendants()
where x.Name.ToLower() == "title"
select x.InnerText).FirstOrDefault();

String desc = (from x in doc.DocumentNode.Descendants()
where x.Name.ToLower() == "meta"
&& x.Attributes["name"] != null
&& x.Attributes["name"].Value.ToLower() == "description"
select x.Attributes["content"].Value).FirstOrDefault();

List<String> imgs = (from x in doc.DocumentNode.Descendants()
where x.Name.ToLower() == "img"
select x.Attributes["src"].Value).ToList<String>();

txturl0.Text = title;
txturl1.Text = desc;
Image1.ImageUrl = imgs[0];



Published at DZone with permission of Sourabh Sharma, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}