解析python中的错误处理

时间:2018-08-18 04:46:08

标签: python xml

import json
import requests
import pprint
from datetime import datetime
import xml.etree.cElementTree as ET
cursor = context.cursor()
cursor.execute("SELECT * FROM table" )
for a in cursor.fetchall():
    data=a[0]
    root = ET.fromstring(a[1].encode('utf-16-be'))
    try:
        e = root.findall('test/element')
        f = root.findall('test/element1')
        for i,j in zip(e,f):
            char_id=i.text.rstrip()
            char_value=j.text.rstrip()
            Id = data
            tic_ID =char_id
            tic_value=char_value
            print(entityId,char_id,char_value)
            cursor.execute("INSERT INTO table  VALUES (?,?,?)", (Id, tic_ID, 
            tic_value))
    except ValueError as error:
        raise ParseError(error)

如何在此代码中处理xml解析错误以插入所有没有错误数据的数据?由于某些原因,我不会使用lxml。

0 个答案:

没有答案