Hello stack overflow friends!
I'm trying to run this code, to download images from urls.
Here's the code:
import requests
import itertools
import pandas as pd
lista = pd.read_excel("link_img_bling.xlsx")
lista = lista.values.tolist()
lista2 = list(itertools.chain(lista))
for img in lista2:
file_name = img.split('/')[-1]
print(f"This is the file name: {file_name}")
r = requests.get(img, stream=True)
if r.status_code == 200:
with open(file_name, 'wb') as f:
for chunk in r:
f.write(chunk)
else:
broken_images.append(img)
The problem is when i transform the dataframe into a list, it returns a list of lists and it breaks my file_name variable. So i've tried to concatenate the list using itertools, but it didn't work, it still returns a list of lists.
Any ideas?