I am trying to get Python to open sites based on a csv file. I checked all of my code individually to make sure it worked and it does but when I introduce this variable from the csv file I am getting the error message below: Here is the code:
import urllib
import urllib.request
from bs4 import BeautifulSoup
import os
import csv
f = open('gropn1.csv')
csv_f = csv.reader(f)
for row in csv_f:
theurl="http://www.grote.com/?s="+csv_f[1] + "&q1=1"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage,"html.parser")
for partno in soup.find('h2',{"class":"single-product-number"}):
print(partno)
for link in soup.find('ul',{"class":"breadcrumbs"}).findAll('a'):
print(link.text)
f.close()
Here is the error:
Traceback (most recent call last):
File "grotestart2.py", line 13, in <module>
theurl="http://www.grote.com/?s="+csv_f[1] + "&q1=1"
TypeError: '_csv.reader' object is not subscriptable
Any help would be greatly appreciated! Thanks