0

I am trying to download all the images in a CSV file to my computer. Unfortunately, it seems that because the first row contains a header instead of a link, it doesn't work. Could you please help me fix my mistake? import csv import requests

with open('abc.csv') as csvfile:
    csvrows = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in csvrows:
        filename = row[1]
        url = row[2]
        print(url)
        result = requests.get(url, stream=True)
        if result.status_code == 200:
            image = result.raw.read()
            open(filename,"wb").write(image)

Below is my abc.csv file:

    identifier                             link           likes_count   company
0   2292512316069378197 https://www.instagram.com/p/B_Qo84ihfiV 9608    Nike
1   2292462538514040606 https://www.instagram.com/p/B_QdohlBQce 9462    Nike
2   2292418655784545069 https://www.instagram.com/p/B_QTp8mhCst 22033   Nike
3   2292372137723669561 https://www.instagram.com/p/B_QJFBSBaw5 14112   Nike
4   2292334760619881771 https://www.instagram.com/p/B_QAlHJBzUr 5974    Nike

... ... ... ... ...

Tony Flager
  • 95
  • 1
  • 8

0 Answers0