Hi All I tried to insert data into mysql database but data could not be insert and there is no error during run the crawl.
My pipeline code is below and pls suggest me how to insert.
Is there any command for scrapy crawl to insert into mysql data same as excel like "scrapy crawl -o datafile.csv -t csv" or simply run the spider like " scrapy crawl spidername"?
Please help me guys i am new in scrapy.
import sys
import MySQLdb
import hashlib
from scrapy.exceptions import DropItem
from scrapy.http import Request
class PagitestPipeline(object):
def __init__(self):
self.conn = MySQLdb.connect("localhost","root"," ","test",charset="utf8", use_unicode=True )
self.cursor = self.conn.cursor()
def process_item(self, item, spider):
try:
self.cursor.execute("INSERT INTO infosec (titlename, standname)
VALUES ('%s', '%s')",
(item['titlename'].encode('utf-8'),
item['standname'].encode('utf-8')))
self.conn.commit()
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
return item