Open zxcsjf opened 2 years ago
修改了代码逻辑:遇到折叠的标签,简介直接把introduction_soup[0:]全部写入,虽然降低了简介可读性,但能保证后面的漫画内容正常爬取。
if not os.path.exists(comic_name): os.mkdir(comic_name) os.chdir(comic_name) print("创建文件夹...完成") with open('作品简介.txt', 'w') as file_handle: # .txt可以不自己新建,代码会自动新建 if len(introduction) == 0: file_handle.write(introduction_soup[0:]) # 写入,遇到简介折叠的标签,introduction是空list else: file_handle.write(introduction[0]) # 写入, file_handle.close() print("写入简介...完成") else: os.chdir(comic_name) # 同层下创建漫画名文件夹并进入 print("进入已存在文件夹") with open('作品简介.txt', 'a') as file_handle: # .txt可以不自己新建,代码会自动新建 if len(introduction) == 0: file_handle.write(introduction_soup[0:]) else: file_handle.write(introduction[0]) file_handle.close() print("写入简介...完成") ```
修改了代码逻辑:遇到折叠的标签,简介直接把introduction_soup[0:]全部写入,虽然降低了简介可读性,但能保证后面的漫画内容正常爬取。