码迷,mamicode.com
首页 > 其他好文 > 详细

博客测试

时间:2018-01-19 19:52:10      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:smart   mem   fail   单列   pad   show   connect   gpo   isp   

技术分享图片
  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 



博客测试

标签:smart   mem   fail   单列   pad   show   connect   gpo   isp   

原文地址:https://www.cnblogs.com/daleyzou/p/8318355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!