I am trying to download some microdata from the Canary Institute of Statistics , specifically the microdata from the Survey on Tourist Expenditure for the first quarter of 2020.
This is what I have tried:
import requests
url = 'http://www.gobiernodecanarias.org/istac/galerias/documentos/C00028A/egt-metodologia-2018-microdatos-2020q1.html'
EGT = requests.get(url)
EGT
And python returns me: <Response [200]>
I have also tried:
import wget
url = 'http://www.gobiernodecanarias.org/istac/galerias/documentos/C00028A/egt-metodologia-2018-microdatos-2020q1.html'
wget.download(url, 'C:\Trabajo\ISTAC_project\ISTAC_python/egt-metodologia-2018-microdatos-2020q1.html')
That generates a file .html
with the address where the microdata is in zip format that I need but it does not download the file.
How can I then download the file?
you can do it like this:
This alternative reads and saves the file to disk. It doesn't unzip it. The end result is that you have a
datos.zip
in your directory.The solution defines a function
download_url
that receives the URL and an output filename. Optionally you can indicate the size of the read buffer.