Download Image from URL list inside Text File

def store_raw_images(file): pathname, filename = os.path.split(file) name = filename[:-4] print('===Gathering '+str(name)+"===") face_link = open(str(file)) # face_image_urls = urllib.request.urlopen(face_link).read().decode() # print('path', pathname) # print('filename', filename) # print(name) # print(extension) if not os.path.exists('Images/'+str(name)): os.makedirs('Images/'+str(name)) for i in face_link: try: url = i.split(" ")[1] index = i.split(" ")[0] print(str(index)+" "+str(url)) result = requests.get(url, stream=True) if result.status_code == 200: image = result.raw.read() open("Images/"+str(name)+"/"+str(index)+".jpg", "wb").write(image) except Exception as e: print(str(e))
Download Image from URL list inside Text File

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.