Get all image links from webpage

We use the module urllib2 to download webpage data. Any webpage is formatted using a markup language known as HTML.

Extracting image links:
To extract all image links use:

from BeautifulSoup import BeautifulSoup
import urllib2
import re

html_page = urllib2.urlopen("http://imgur.com")
soup = BeautifulSoup(html_page)
images = []
for img in soup.findAll('img'):
    images.append(img.get('src'))

print(images)

Explanation
First we import the required modules:

from BeautifulSoup import BeautifulSoup
import urllib2
import re

We get the webpage data using:

html_page = urllib2.urlopen("http://imgur.com")

Then we extract all image links using:

images = []
for img in soup.findAll('img'):
    images.append(img.get('src'))

Finally we print the links:

print(links)