0
이 코드를 사용하여 로컬로 저장된 HTML 파일의 일부를 추출하고 축약 된 새 문서를 .txt 파일로 저장합니다.RegEX로 일반 HTML 파일 자르기
Traceback (most recent call last):
File "C:/Users/6930p/PycharmProjects/untitled/Versuch/CutFile.py", line 16, in <module>
extractor()
File "C:/Users/6930p/PycharmProjects/untitled/Versuch/CutFile.py", line 14, in extractor
out.write(cut)
File "C:\Users\6930p\Anaconda3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 241205-241210: character maps to <undefined>
누구나 아이디어 문제가 무엇 :
import glob
import os
import re
def extractor():
os.chdir(r"F:\Test") # the directory containing your html
for file in glob.iglob("*.html"): # iterates over all files in the directory ending in .html
with open(file, encoding="utf8") as f, open((file.rsplit(".", 1)[0]) + ".txt", "w", encoding="utf8") as out:
contents = f.read()
extract = re.compile(r'(Start).*?End', re.I | re.S)
cut = extract.sub('', contents)
if re.search(extract, contents) is not None:
out.write(cut)
out.close()
extractor()
내가 어떤 인코딩 문제가 얻을 할 몇 가지 파일 그러나 내 파일의 대부분 잘 작동? 사용하여 생각했습니다 encoding="utf8"
인코딩에 문제가 없습니다 ...
도움을 주셨습니다.