加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scrap_file.py 951 Bytes
一键复制 编辑 原始数据 按行查看 历史
Jérôme Krell 提交于 2019-10-10 14:22 . Reformat Code by PyCharm-Community
# Author : RIZWAN AHMAD
# pip3 install requests
import requests
# Function for download file parameter taking as url
def download(url):
f = open('file_name.jpg', 'wb') # opening file in write binary('wb') mode with file_name.ext ext=extension
f.write(requests.get(url).content) # Writing File Content in file_name.jpg
f.close()
print("Succesfully Downloaded")
# Function is do same thing as method(download) do,but more strict
def download_2(url):
try:
response = requests.get(url)
except Exception:
print('Failed Download!')
else:
if response.status_code == 200:
with open('file_name.jpg', 'wb') as f:
f.write(requests.get(url).content)
print("Succesfully Downloaded")
else:
print('Failed Download!')
url = 'https://avatars0.githubusercontent.com/u/29729380?s=400&v=4' # URL from which we want to download
download(url)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化