店播爬取Python脚本

mysql_dy_live.py 524B

123456789101112131415161718
  1. from libs.db_mysql import DbMysql
  2. class MysqlDyLive(DbMysql):
  3. table = 'douyin_live'
  4. # 获取直播数据
  5. def get_live_info(self, room_id):
  6. sql = 'SELECT id,room_id,status FROM ' + self.table + ' WHERE `room_id`=%s LIMIT 1'
  7. try:
  8. # 执行SQL
  9. self.cursor.execute(sql, [room_id])
  10. return self.cursor.fetchone()
  11. finally:
  12. self.db.commit() # 提交
  13. self.cursor.close() # 关闭cursor
  14. self.db.close() # 关闭db连接