0
이 XML 파일에는 utf-8 인코딩이 있습니다.ElementTree UTF-8 소스 파일에서 XML 구문 분석
<?xml version="1.0" encoding="UTF-8"?>
<Items>
<Item>
<Cikkszam>00008</Cikkszam>
<EAN/>
<Megjegyzes>BISK</Megjegyzes>
<Leiras1>Bisk Ontario, Dakota szappantartóhoz</Leiras1>
<Leiras2>műanyag betét</Leiras2>
<CikkTipus>07 </CikkTipus>
<ME_>db </ME_>
<Tipus>Választható</Tipus>
<A_ar>338</A_ar>
<B_ar>0</B_ar>
<C_ar>0</C_ar>
<D_ar>0</D_ar>
<E_ar>0</E_ar>
<Tenyl_keszl_>0</Tenyl_keszl_>
<Visszaig_>0</Visszaig_>
<Diszponalt>0</Diszponalt>
<Szabad_keszlet>0</Szabad_keszlet>
</Item>
</Items>
나는이 파이썬 코드를 가지고 :
from xml.etree.ElementTree import ElementTree
#import xml.etree.ElementTree
items = ElementTree().parse('proba.xml'.encode('utf8'))
#items = xml.etree.ElementTree.parse('proba.xml')
products = items.findall("Item")
for product in products:
print product.find("Leiras1").text
내가 다음 오류 메시지가있어 내 스크립트 파일을 실행하면 :
C:\Python27>python read_xml_orig.py
Bisk Ontario, Dakota szappantartóhoz
Bisk Álló Wc kefe és papír tartó talpas
Bisk sarok szappantartó króm
Bisk sarok szappantartó króm
Bisk üveg pohár pót
Bisk ONTARIO üveg folyékony
Bisk ONTARIO üveg polc
Bisk ONTARIO dupla
Bisk ONTARIO rud
Traceback (most recent call last):
File "read_xml_orig.py", line 7, in <module>
print product.find("Leiras1").text
File "C:\Python27\lib\encodings\cp850.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u0151' in position
21: character maps to <undefined>