CD_NS
CD_NS

Reputation: 319

How to fetch Reddit post from a scraped csv

I have a csv file with Reddit ID. In first column there may be 2-6 ids but in second column there is always 2 IDs. I have to write a script so that i can fetch the posts from IDs for the both column.

pic1

Your help will be much appreciated.

Upvotes: 0

Views: 134

Answers (1)

fiordiconio
fiordiconio

Reputation: 64

So first of all you need to read that file.

import csv
with open('yourfilename.csv', mode ='r') as file:
csvFile = csv.reader(file)

Taken from here

Next you would want to split each column to a list, so that you can scrape multiple ids

idList = []
for line in csvFile: # loop each line
  for columns in line: # loop each column
    for element in columns.split(' '): # loop each element
      idList.append(element)

print(idList)

Taken from here

Upvotes: 2

Related Questions