My python code which picks links from row 1 and date from row 2 in order to run to_scrape function which requires both link and date, has the last output running infinitely. What is the best way to read and have the links+date (both columns of row) work/get data without getting the loop stuck
start = 0
end = 2
csvfile = open('file.csv', 'r')
csvFileArray = []
for row in csv.reader(csvfile):
csvFileArray.append(row[0])
csvFileDate = []
for row in csv.reader(csvfile):
csvFileDate.append(row[1])
csvfile.close()
alums = csvFileArray[start:end]
alumdate = csvFileDate[start:end]
for i in alums:
for j in alumdate:
start+=1
print(i)
print(start)
to_scrape(i,j)
Instead of the following (what you did):
for i in alums:
for j in alumdate:
start+=1
print(i)
print(start)
to_scrape(i,j)
You should use the zip
function, it can iterate through multiple sequences in parallel:
for i, j in zip(alums, alumdate):
start+=1
print(i)
print(start)
to_scrape(i,j)