1. 程式人生 > >博客測試

博客測試

round 數據庫 brush process 數據庫名 execute 分享圖片 log cin

技術分享圖片
  1     def __init__(self):
  2     # 獲取setting主機名 端口號和數據庫名
  3     self.host = settings[‘MySQL_HOST‘]
  4     self.port = settings[‘MySQL_PORT‘]
  5     self.dbname = settings[‘MySQL_DBNAME‘]
  6     self.conn = MySQLdb.connect(host=‘localhost‘, port=3306, db=‘douban‘, user=‘root‘, passwd=‘root‘,charset=‘utf8‘)
  7
self.cur = self.conn.cursor() 8
View Code● 標記展開 def __init__(se
    def __init__(self):
        # 獲取setting主機名 端口號和數據庫名
        self.host = settings[‘MySQL_HOST‘]
        self.port = settings[‘MySQL_PORT‘]
        self.dbname = settings[‘MySQL_DBNAME‘]
        self.conn = MySQLdb.connect(host=‘localhost‘, port=3306, db=‘douban‘, user=‘root‘, passwd=‘root‘,charset=‘utf8‘)
        self.cur = self.conn.cursor() user=‘root‘, passwd=‘root‘,charset=‘utf8‘)
        self.cur = self.conn.cursor()








技術分享圖片
def process_item(self, item, spider):
    try:
        sql = "INSERT INTO doubanmovies(title,bd,star,quote_mv,img_url) VALUES(\‘%s\‘,\‘%s\‘,%f,\‘%s\‘,\‘%s\‘)" %(item[‘title‘],item[‘bd‘],float(item[‘star‘]),item[‘quote‘],item[‘img_url‘])
        # sql = "INSERT INTO doubanmovies(title,bd,star,quote_mv,img_url) VALUES(‘‘,‘‘,8.8,‘‘,‘‘)"
        self.cur.execute(sql)
        self.conn.commit()
    except Exception, e:
        print "----------------------inserted faild!!!!!!!!-------------------------------"
        print e.message

    return item



● 年後展開 def close_spider(self, spider): print ‘-----------------------quit-------------------------------------------‘ self.cur.close() self.conn.close()返回頂部收縮


技術分享圖片




● 年後展開 def close_spider(self, spider): print ‘-----------------------quit-------------------------------------------‘ self.cur.close() self.conn.close()


  1    def close_spider(self, spider):
  2     print ‘-----------------------quit-------------------------------------------‘
  3     self.cur.close()
  4     self.conn.close()
  5 
返回頂部收縮



返回頂部收縮

博客測試