cp6_p113_Download A Single File

# The urllib library, used to retrieve the content of webpages
# also contains functions to retrieve the content of files
from urllib.request import urlretrieve
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen('http://www.pythonscraping.com')
bs = BeautifulSoup(html, 'html.parser')
imageLocation = bs.find('a', {'id':'logo'}).find('img')['src']
urlretrieve(imageLocation, 'logo.jpg')

#run
#python cp6_p112.py

# This works well if you need to download only a single file
# and know what to call it and what the file extension is.

cp6_p113_Download A Single File