python url下载文件,使用python下载带有URL的文件

下载文件:

In [1]: import requests

In [2]: url = 'https://assets.publishing.service.gov.uk/government/uploads/syste

...: m/uploads/attachment_data/file/959864/COVID-19-transport-use-statistics.

...: ods'

In [3]: with open('COVID-19-transport-use-statistics.ods', 'wb') as out_file:

...: content = requests.get(url, stream=True).content

...: out_file.write(content)

pip install pandas-ods-reader

然后:

In [4]: from pandas_ods_reader import read_ods

In [5]: df = read_ods('COVID-19-transport-use-statistics.ods', 1)

In [6]: df

Out[6]:

Department for Transport statistics ... unnamed.9

0 https://www.gov.uk/government/statistics/trans... ... None

1 None ... None

2 Use of transport modes: Great Britain, since 1... ... None

3 Figures are percentages of an equivalent day o... ... None

4 None ... Percentage

.. ... ... ...

390 Transport for London Tube and Bus ... None

391 Buses (excl. London) ... None

392 Cycling ... None

393 Any other queries ... None

394 Media enquiries ... None

如果你想用csv,你可以把它保存为csv

df.to_csv('my_data.csv', index=False)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值