Created
September 22, 2014 09:08
-
-
Save newbiethetest/472c1d5362a97687474d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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