Possible Duplicate:
convert list to string to insert into my sql in one row in python scrapy
Is this script correct. I want to insert the scraped out h2,h3,meta data directly into mysql database. The code below does not work correctly. Can someone please provide a solution to this. I think the problem is with the for loop.
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//ul/li')
items = [site.select('//h2').extract()]
item = [site.select('//h3').extract()]
item1 = [site.select('//meta').extract()]
for index,index1,index2 in range (len( items)),range(len(item)),range(len(item1)):
con = MySQLdb.connect(
host="localhost",
user="dreamriks",
passwd="dreamriks",
db="scraped_data"
)
cur = con.cursor()
str = items[index]
str1 = item[index1]
str2 = item1[index2]
cur.execute("""Insert into heads(h2,h3,meta) Values(%s,%s,%s)""",(str,str1,str2))
con.commit()
con.close()
The error that comes is:
for index,index1,index2 in range (len( items)),range(len(item)),range(len(item1)):
exceptions.ValueError: need more than 1 value to unpack