磕拉酱

自整理36大院文包资源-古剑二

#古二文包#

啊,咋回事啊,这个文章被删了,是因为有链接吗,重发一遍。我真的好爱古剑二,爱了好多年。

这个是 #36大院# 的那个解压之后8g的原始数据库文包里的#古剑二#部分。

原来的文件标题都是url,根本不知道哪篇是哪篇。于是想吃粮的我写了个python程序,解析每个文件的源代码,然后重命名为tag+cp+文名,然后还改成了html格式,这个格式可以直接用浏览器打开,还可以直接推送到kindle变成文字版(推送转格式的话,记得邮件名是convert)。

ps:文包已按照cp分了文件夹。

希望大家吃粮愉快。



文包资源:链接已删除。

本来想为我圈添砖加瓦。

被科普了授权问题,文包链接已删。

放上Python源代码吧,大家有需要自取即可。我不是学计算机的,代码水平估计不行,只是能用罢了,大佬见了要笑话的程度


#!/usr/bin/python

# -*- coding: utf-8 -*-

import os

import re

import sys

from bs4 import BeautifulSoup

files = os.listdir(os.getcwd())#分解文件名为名字+后缀,用来区分需要重命名哪些文件以及修改后缀

for name in files:

    a = os.path.splitext(name)

#print (name)

if a[0] =='showmsg':

try:

            print(name)

            f = open(name,"rb")

            htmlf = f.read().decode('gb18030','ignore')#编码

            soup = BeautifulSoup(htmlf,"lxml")

#soup = BeautifulSoup(open(name),"lxml",from_encoding="gb18030")

            new1= soup.title.string#解析出html文件的title(字符串形式)

#new1= soup.title.encode('gb2312')

            new1=new1.replace('/','][')

            new1=new1.replace(':','')

            new1=new1.replace('【','[')

            new1=new1.replace('】',']')

            new1=new1.replace('?','')

            new1=new1.replace('|','')

            new1=new1.replace('*','')

            new1=new1.replace('•','')

            new1=new1[:-14]

#分类对文件重命名

if'&page='in name:

                num=re.findall(r'page=(\d+)',name)

                newname = new1 + num[0] +'.html'#顺便修改文件类型为html

else:

                newname = new1 + '.html'

#newname = new1 + name[:] +'.html'

#newname = soup.title.string

print (newname)

            f.close()

            os.rename(name,newname)

except(FileExistsError,FileNotFoundError,UnicodeEncodeError,OSError):#错误类型

#os.remove(name)#本来想删除来着,但是当出现编码错误的时候,文件删除会提示正在别的地方占用,禁止删除。估计和句柄有关,但不想解决了,太复杂。



评论(52)

热度(356)

  1. 共14人收藏了此文字
只展示最近三个月数据