Dec-19-2018, 05:10 AM
hi,
I have a csv with around 2 lakhs url to download images from them.I am reading a csv and downloading images:
below is my code:
any examples or alteration in code is appreciable . Please help
I have a csv with around 2 lakhs url to download images from them.I am reading a csv and downloading images:
below is my code:
from bs4 import BeautifulSoup import requests import csv import urllib.request import os final_data = [] def get(url, values): res = requests.get(url, data=values) d = res.status_code if d!=200: print("Invalid Link") else: print("Valid link") data = res.text return data def readfile(): with open("./plans.csv", "r") as csvfile: reader = csv.reader(csvfile) next(reader) for row in reader: lists = row[0] ind = row[1]+".jpg" mj = os.path.abspath(ind) d = requests.get(lists) sublist = [] try: d = urllib.request.urlretrieve(lists, ind) sublist.append(mj) sublist.append(lists) except Exception as e: sublist.append(mj) sublist.append(e) final_data.append(sublist) return final_data def writefiles(alldata, filename): with open ("./"+ filename, "w") as csvfile: csvfile = csv.writer(csvfile, delimiter=",") csvfile.writerow("") for i in range(0, len(alldata)): csvfile.writerow(alldata[i]) def main(): readfile() writefiles(final_data, "downloads.csv") main()It is downloading images , but how can i make this code to run fast, like more fast.
any examples or alteration in code is appreciable . Please help