Reputation: 89
i have a csv and i'd like to find every occurrence of 'http://'. using the code below i get nothing. at this point, i'd like to know why i'm not getting any results at all (not even the 'hi' is bring printed). i'm a noob and it's just not making sense to me. explanations are welcome, links are fine but only if they help me understand...
import csv
with open('a_bunch_of_urls_and_other_stuff.csv', 'rb') as f:
reader = csv.reader(f, delimiter=',')
# remove results that dont have 'http://'
for result in reader:
# print result # this prints everything from the cvs
# print result[2] # this prints out the column with urls
if result[2] == 'http://':
print 'hi'
Upvotes: 1
Views: 50
Reputation: 828
I am assuming you trying to check if result[2] contains 'http://'.
You can try:
if "http://" in result[2]:
print result[2]
Upvotes: 1