Parsing Error xml.parsers.expat.ExpatError: not well-formed (invalid token): line X column Y

这个问题困扰我很久啦

首先你要确定不是xml格式原因,然后可以用我的方法解决

我的是因为xml文件中含有非法字符

下面是我的解决方案:

import os

import re

listdir =['D:/test']

for i in listdir:

for root, dirs, files in os.walk(i):

    for file in files:
	
        url = str(root) + str("/") + str(file)
		
        print(url)
		
        f = open(url, encoding="utf-8")
		
        text = f.read()
		//这行是重点
        text = re.sub(u"[\x00-\x08\x0b-\x0c\x0e-\x1f]+", u"", text)
		
        f.close()
		
        with open(url,"w",encoding="utf-8") as f1:
		
            f1.write(text)

转载于:https://my.oschina.net/u/2511906/blog/3036955

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值