# Simple Python script to download a file. Used as a fallback# when other more reliable methods fail.#from __future__ import print_functionimport systry:from requests import getexcept ImportError:try:from urllib.request import urlretrieveUSING = "urllib.request.urlretrieve"except ImportError:try:from urllib import urlretrieveUSING = "urllib.retrieve"except ImportError:print("Python at", sys.executable, "is not suitable","for downloading files.", file=sys.stderr)sys.exit(2)else:USING = "requests.get"def urlretrieve(url, filename):r = get(url, stream=True)r.raise_for_status()with open(filename, 'wb') as f:for chunk in r.iter_content(chunk_size=1024):f.write(chunk)return filenameif __name__ == '__main__':if len(sys.argv) != 3:print("Usage: urlretrieve.py [url] [filename]", file=sys.stderr)sys.exit(1)URL = sys.argv[1]FILENAME = sys.argv[2]print("Downloading from", URL, "to", FILENAME, "using", USING)urlretrieve(URL, FILENAME)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。