我有一个90年代中期创建的.html文件集合,其中包含大量的韩文文本.HTML缺少字符集元数据,因此当然所有韩文文本都无法正确呈现.以下示例将全部使用相同的文本摘录.
╙╦╙╦№бя└К▓щ╥НВь╕цль▒Ф▓щ╥НВь╕цль▒Ф
在<head>中没有字符集元数据的情况下,浏览器将其呈现为:
Ó˼¼¡ÀÀ²²Òììæ««±"²éÒ,ì¸æ«ì±"
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
Run Code Online (Sandbox Code Playgroud)
产生以下内容,这是难以辨认的废话(由母语人士证实):
沓∽핅꿴 レレ콛꿴 レレ콛
我已经尝试了所有历史韩国字符集的这种方法,每个字符集都会产生类似的不成功结果.我也尝试通过Beautiful Soup解析并升级到UTF-8,这也失败了.
在Emacs中查看文件似乎很有希望,因为它显示了较低级别的文本编码.以下是相同的文本示例:
\ 323\313\274\374\241\357\300\212\262\351\322\215\202\354\270\346\253\354\261\224\262\3\51\322\215\202\354\270\346\253\354\261\224
如何识别此文本编码并将其提升为UTF-8?
我有一个脚本,每晚运行一次,以将大量内容存储在服务器上的特定目录中。这是我用于该核心部分的功能:
def get_size(start_path = '.'):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
try:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
print str(total_size)+" bytes / "+str(size(total_size))+" counted"+" <------------ current position: "+start_path+" : "+f
for location in locations_dict:
if locations_dict[location][1] != "":
print str(location)+": "+str(size(locations_dict[location][1]))
except OSError, e:
print e
return total_size
Run Code Online (Sandbox Code Playgroud)
由于某些原因,当我手动运行时,我得到一个不同的值
$ du -hc [path to dir]
Run Code Online (Sandbox Code Playgroud)
使用Python,我得到20551043874445字节(转换为20.5 TB)。随着du我得到28 TB(我现在重新运行没有-h得到以字节为单位的值)。
显然,Python函数缺少某些内容,但是我不确定是什么或如何。有任何想法吗?