'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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1