def from_url(cls, url, callback=agate.Table.from_csv, binary=False, **kwargs):
"""
Download a remote file and pass it to a :class:`.Table` parser.
:param url:
URL to a file to load.
:param callback:
The method to invoke to create the table. Typically either
:meth:`agate.Table.from_csv` or :meth:`agate.Table.from_json`, but
it could also be a method provided by an extension.
:param binary:
If :code:`False` the downloaded data will be processed as a string,
otherwise it will be treated as binary data. (e.g. for Excel files)
"""
r = requests.get(url)
if binary:
content = six.BytesIO(r.content)
else:
if six.PY2:
content = six.StringIO(r.content.decode('utf-8'))
else:
content = six.StringIO(r.text)
return callback(content, **kwargs)
评论列表
文章目录