def delede_novel(novel_id): #小说表 find_novel = "select id,title,author,pic,position from b_novel where id =%s" cur.execute(find_novel, novel_id) novel_info_t = cur.fetchall() for novel_info in novel_info_t: #记录删除 if novel_info[4] == 0: hot = " " else: hot = "热门小说" open('delede_7k_xb.txt', 'a', encoding='utf-8').write('删除小说名:' + novel_info[1] + ' 作者:' + novel_info[2] + ' hot:' + hot + '\n') try: # 删除封面文件 img_path = path_config()[0] + novel_info[3].replace( '/upload/novel_img/', '') os.remove(img_path) except Exception: pass b_novel = "delete from b_novel where id =%s" cur.execute(b_novel, novel_id) #小说章节 cha_sql_name = 'b_chapter_{}'.format(novel_id // 1000 + 1) find_conent = "select content from {} where novel_id =%s".format( cha_sql_name) % novel_id cur.execute(find_conent) cha_path_t = cur.fetchall() for cha_path in cha_path_t: try: # 删除章节文件 txt_path = path_config()[1] + cha_path[0].replace( '/upload/chapter_txt/', '') os.remove(txt_path) except Exception: pass delede_cha = "delete from %s where novel_id=%s" % (cha_sql_name, novel_id) cur.execute(delede_cha) #删除换源 f_source = "select id from b_source where novel_id = %s" cur.execute(f_source, novel_id) sou_id_t = cur.fetchall() for sou_id in sou_id_t: sou_sql_name = 'b_source_list_{}'.format(sou_id[0] // 500 + 1) delete_sou_list = "delete from %s where source_id = %s" % ( sou_sql_name, sou_id[0]) cur.execute(delete_sou_list) delete_sou = "delete from b_source where novel_id =%s" cur.execute(delete_sou, novel_id) conn.commit() print(novel_info[1], '删除成功')
def __init__(self): sql_date = sql_config() self.conn = pymysql.Connect( host=sql_date["host"], port=sql_date["port"], #数据库名: db=sql_date["db"], user=sql_date["user"], passwd=sql_date["passwd"], charset=sql_date["charset"]) self.cur = self.conn.cursor() path=path_config() self.txt_path=path[1]
def open_spider(self, spider): sql_date = sql_config() self.conn = pymysql.Connect( host=sql_date["host"], port=sql_date["port"], #数据库名: db=sql_date["db"], user=sql_date["user"], passwd=sql_date["passwd"], charset=sql_date["charset"]) self.cur = self.conn.cursor() path = path_config() self.img_path = path[0] self.txt_path = path[1]
def __init__(self): self.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36"} self.s=requests.Session() sql_date = sql_config() self.conn = pymysql.Connect( host=sql_date["host"], port=sql_date["port"], #数据库名: db=sql_date["db"], user=sql_date["user"], passwd=sql_date["passwd"], charset=sql_date["charset"]) self.cur = self.conn.cursor() path=path_config() self.txt_path=path[1] f_m_i = "select max(id) from b_novel" self.cur.execute(f_m_i) self.max_id = self.cur.fetchone()[0]