Saturday, December 13, 2014

How to download a file from the internet

Code
import urllib
#imports the urllib library

url = 'https://www.spdrs.com/site-content/xls/XOP_All_Holdings.xls'
#defining the url where the file we want to download is. 

destination = 'xop_holdings.xls'
#defining the destination where you want the file saved to

urllib.urlretrieve(url, destination)
#this downloads the file.  This function returns a tuple containing the filename and headers. 

No comments:

Post a Comment