【发布时间】:2020-07-31 10:30:29
【问题描述】:
我正在尝试自动下载文件并保存。应该很容易,但我发现了一些困难。
理论上应该很容易here,你点击自动下载文件。
我尝试了不同的方法(如在 here 或 enter link description here 等不同的帖子中发现的)。这是我当前代码的几个示例:
选项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)
选项 B)
xl_df = pd.read_excel(url,
sheet_name='Table 5 - Testing',
skiprows=range(5),
skipfooter=0)
在这两种情况下我都会得到
urllib.error.URLError: <urlopen error [Errno 60] Operation timed out>
有什么建议吗? 非常感谢!
【问题讨论】:
标签: python-3.x pandas download python-requests xlsx