【发布时间】:2018-03-08 18:51:58
【问题描述】:
我的目的是从这个网站下载数据: http://transoutage.spp.org/
打开本网站时,在网页底部,有一个说明用于说明如何自动下载数据。例如: http://transoutage.spp.org/report.aspx?download=true&actualendgreaterthan=3/1/2018&includenulls=true
我写的代码是这样的:
import requests
ul_begin = 'http://transoutage.spp.org/report.aspx?download=true'
timeset = '3/1/2018' #define the time, m/d/yyyy
fn = ['&actualendgreaterthan='] + [timeset] + ['&includenulls=true']
fn = ''.join(fn)
ul = ul_begin+fn
r = requests.get(ul, verify=False)
既然,如果你输入网址, http://transoutage.spp.org/report.aspx?download=true&actualendgreaterthan=3/1/2018&includenulls=true, 进入 Chrome,它会自动下载 .csv 文件中的数据。我不知道如何继续我的代码。
请帮帮我!!!!
【问题讨论】:
-
好吧,这行得通吗?它会给出错误吗?它是否在
r中给出了有用的返回值或状态码? -
您要查找的数据包含在
r.content中 - 只是open一个文件和write它的内容。我刚刚试了一下,它生成了一个有效的 CSV。 -
你可以使用python的csv模块来处理接收到的csv数据。检查docs.python.org/3.0/library/csv.html