# 判断是否有图片文件 cos_file_img_list = [] if not img_href_list: pass else: for img_url in img_href_list: print(img_url) suffix = '' file_type = '' # 判断这个url是什么类型的文件并添加cos渠道 if img_url.split(".")[-1].lower() == 'pdf': suffix = "PDF" file_type = 'text/pdf' elif img_url.split(".")[-1].lower() == 'doc' or img_url.split(".")[-1].lower() == 'docx': suffix = 'DOCX' file_type = 'text/docx' elif img_url.split(".")[-1].lower() == 'xls' or img_url.split(".")[-1].lower() == 'xlsx': suffix = 'excel' file_type = 'text/xlsx' elif img_url.split('.')[-1].lower() == 'jpg' \ or img_url.split('.')[-1].lower() == 'png'\ or img_url.split('.')[-1].lower() == 'jpeg'\ or img_url.split('.')[-1].lower() == 'gif'\ or img_url.split('.')[-1].lower() == 'bmp'\ or img_url.split('.')[-1].lower() == 'tiff'\ or img_url.split('.')[-1].lower() == 'webp'\ or img_url.split('.')[-1].lower() == 'heic'\ or img_url.split('.')[-1].lower() == 'heif'\ : suffix = 'IMG' file_type = f'Image/{img_url.split(".")[-1].lower()}' elif img_url.split('.')[-1].lower() == 'zip': suffix = 'ZIP' file_type = 'text/zip' elif img_url.split('.')[-1].lower() == 'mp4': suffix = 'videos' file_type = 'video/mp4' # 将所有的图片和文件追加到列表中全部运行完后开始上传cos self.requests_content([img_url, suffix, file_type, title + img_url.split("/")[-1]]) # 拼接cos链接 cos_file_img_list.append( f"https://data-crawler-1325559378.cos.ap-beijing.myqcloud.com/{suffix}/{wangzhanmingzi}/{title + img_url.split('/')[-1]}" )
标签:cos,suffix,img,url,lower,传到,split,file,理性 From: https://www.cnblogs.com/wolvies/p/18383286