爬取某网站时,某字符段报错出现如下报错:openpyxl.utils.exceptions.ILlegalCharacterError: div class="content-box">[腾讯官方专业国服加速器] <br />
原因分析:
根据提示字段,此种报错,说明该字段中的字符串存在非法的字符,导致无法使用openpyxl模块写入Excel。
解决方法:
1.找到如图所示的cell.py文件,此案例的文件路径 "c:\Users 11\AppDatalocal Proqrams PythonlPython311 Llib site-packages openpyxl cell cell.py",
2.搜索 ILLEGAL_CHARACTERS_RE = re.compile(r'[\000- 010]1[\013- 014]1[\016-(037]'),确认是否存在此句非法字符的处理语句,无则加上。
3.回到执行文件,在文件头加上以下语句:
import re ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
4.在执行文件需要处理的字段添加以下处理语句:如,此案例需要处理的字段是context和version_note;
text = ILLEGAL_CHARACTERS_RE.sub(r'', text)
5.保存后,重新执行,运行无报错即解决!
参考文档:
1.https://blog.csdn.net/qq_45538469/article/details/113446987
2.https://www.cnblogs.com/hengdin/p/16996512.html
- ILlegalCharacterError quot content-box exceptions openpyxlillegalcharactererror quot content-box exceptions quot exception rabbitmq reason outofmemoryerror quot exception thread bindingexception quot exception statement messagingexception quot exception connect version unsupportedclassversionerror quot exception quot installation exception occurred noclassdeffounderror quot serverfactory exception unsatisfiedlinkerror quot exception thread classnotfoundexception quot exception thread