python字符分割
def download_file(file_url):
f = requests.get(file_url,headers = headers)
file_name = file_url.split('/')[-1]
with open(file_name,'wb') as code:
code.write(f.content)
提交的file_url时这个格式的http://xxxx/xxx/xx/x//2019/02/13/20190213988442_lcnsgF.jpg,我需要下载并自动保存,需要自动通过url取出20190213988442_lcnsgF.jpg作为文件名
str.sqlit(字符)表示将str用字符分割,默认全部分割
由于20190213988442_lcnsgF.jpg在最后一个,所以代码中直接写[-1]取出文件名下载即可