[source code] Python Programming Tutorial - 22 - Download an Image from the Web

+4 Bucky Roberts · September 1, 2014

import random
import urllib.request


def download_web_image(url):
    name = random.randrange(1, 1000)
    full_name = str(name) + ".jpg"
    urllib.request.urlretrieve(url, full_name)

download_web_image("https://buckysroom.org/photos/users/2/resized/2463a86fdf42a1681c66ba8fd6789f9d.jpg")

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
-1 Gary Murphy · September 10, 2014
Hey Bucky,

I went to install urllib.request but it  doesn't appear in the list of available packages.  I use Python 2.7 at the moment because of a course I'm doing at the moment and someone mentioned in the Youtube comments to use the urllib package, but that one doesn't appear either.  There's a whole bunch of other urllib packages (eg. urllib2, urllib3, urllibcache, etc..), but I don't know whether they'll have what I need.  Any ideas?
  • 1
  • 2

Python

106,995 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator