Skip to content

Instantly share code, notes, and snippets.

@newbiethetest
Created September 22, 2014 09:08
Show Gist options
  • Save newbiethetest/472c1d5362a97687474d to your computer and use it in GitHub Desktop.
Save newbiethetest/472c1d5362a97687474d to your computer and use it in GitHub Desktop.
class MysqlStordPipeline(object):
def __int__(self):
self.connect=MySQLdb.connect('root','123654','niaoyundb','localhost',charset="utf8", use_unicode=True)
self.cursor=self.connect.cursor()
def process_item(self,item,spider):
try:
self.cursor.execute("""INSERT INTO niaoyunTable (title, href)
VALUES (%s, %s)""",
(item['title'].encode('utf-8'),
item['href'].encode('utf-8')))
self.conn.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