from urllib import request
def download(url,isPicture=False):
'''
:param url:
:param isPicture:
:return:
'''
file_name=url.split('/')[-1]
response=request.urlopen(url)
content=response.read()
if isPicture:
with open(file_name,'wb') as fp:
fp.write(content)
else:
content=content.decode('utf-8')
with open(file_name,'w',encoding='utf-8') as fp:
fp.write(content)
download('https://www.baidu.com/img/bd_logo1.png',isPicture=True)
网络通信
最新推荐文章于 2024-05-04 18:47:55 发布