0

I am trying to download a file automatically and save it. It is suppossed to be easy but I am founding some difficulties.

In theory is supposed to be easy here, you click automatically you download the file.

I have try different ways (as found in diffeent posts such as here or enter link description here). Here a couple of example of mhy current code:

Option A)

url = "https://www.gov.scot/binaries/content/documents/govscot/publications/statistics/2020/04/trends-in-number-of-people-in-hospital-with-confirmed-or-suspected-covid-19/documents/trends-in-number-of-people-in-hospital-with-confirmed-or-suspected-covid-19/trends-in-number-of-people-in-hospital-with-confirmed-or-suspected-covid-19/govscot%3Adocument/HSCA%2B-%2BSG%2BWebsite%2B-%2BIndicator%2BTrends%2Bfor%2Bdaily%2Bdata%2Bpublication.xlsx"

response = requests.get(url,stream=False)
with open(dowload_folder_name, 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)

Option B)

xl_df = pd.read_excel(url,
                       sheet_name='Table 5 - Testing',
                       skiprows=range(5),
                       skipfooter=0)

In both cases I just get

urllib.error.URLError: <urlopen error [Errno 60] Operation timed out>

Any suggestion, please? Many thanks!

Rafael Valero
  • 2,736
  • 18
  • 28

1 Answers1

1
import requests


def main(url):
    r = requests.get(url)
    print(r)
    with open("data.xlsx", 'wb') as f:
        f.write(r.content)


main("https://www.gov.scot/binaries/content/documents/govscot/publications/statistics/2020/04/trends-in-number-of-people-in-hospital-with-confirmed-or-suspected-covid-19/documents/trends-in-number-of-people-in-hospital-with-confirmed-or-suspected-covid-19/trends-in-number-of-people-in-hospital-with-confirmed-or-suspected-covid-19/govscot%3Adocument/HSCA%2B-%2BSG%2BWebsite%2B-%2BIndicator%2BTrends%2Bfor%2Bdaily%2Bdata%2Bpublication.xlsx")

enter image description here