Try using this pipeline..
http://snipplr.com/view/66986/mysql-pipeline/
Середа, 16 квітня 2014 р. 13:35:34 UTC+3 користувач masroor javed написав:
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"scrapy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/scrapy-users.
For more options, visit https://groups.google.com/d/optout.