I want to know how facebook can extract images from given link. If you could please help me. Here is screen of what I mean. Facebook screen
You should read up on the Document Object Model:
https://en.wikipedia.org/wiki/Document_Object_Model
This is an extremely general question, and there are many, many ways to do it. Jquery's find() will do it, as an example, if you search for an img tag. Pretty much every language has a library for navigating the DOM. Looking at the tagged languages in your question, you've got PHP's DomDocument and python's xml.dom. If you're super new to this stuff, you should look into graph theory and specifically tree data structures, because that's the core idea of DOM.