Skip to content

Instantly share code, notes, and snippets.

@newbiethetest
Created September 23, 2014 05:19
Show Gist options
  • Save newbiethetest/23dd1ebe61e9448906ee to your computer and use it in GitHub Desktop.
Save newbiethetest/23dd1ebe61e9448906ee to your computer and use it in GitHub Desktop.
class MysqlStordPipeline(object):
def __init__(self):
self.connect=MySQLdb.connect('localhost','root','123654','niaoyundb',charset='utf8', use_unicode=False)
self.cursors=self.connect.cursor()
def process_item(self,item,spider):
try:
#self.cursors.execute("select version()")
sql=''' INSERT INTO `niaoyunTable` (title, href) VALUES ("%s", "%s")'''%(item['title'],item['href'])
self.cursors.execute(sql)
self.connect.commit()
except MySQLdb.Error,e:
print "Error %d: %s" % (e.args[0], e.args[1])
return item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment