lxml.etree.iterparse 함수를 사용하여 다음 파이썬 파일을 구문 분석하려고합니다.큰 xml 파일을 파이썬으로 구문 분석하기 - etree.parse 오류
"sampleoutput.xml"
<item>
<title>Item 1</title>
<desc>Description 1</desc>
</item>
<item>
<title>Item 2</title>
<desc>Description 2</desc>
</item>
은 내가 etree.iterparse (MYFILE) 나는 MYFILE = 개방 ("/ 사용자/에릭/데스크탑/wikipedia_map했다 호출하기 전에 Parsing Large XML file with Python lxml and Iterparse
의 코드를 시도 /sampleoutput.xml","r ")
그러나 다음과 같은 오류를 회전
Traceback (most recent call last):
File "/Users/eric/Documents/Programming/Eclipse_Workspace/wikipedia_mapper/testscraper.py", line 6, in <module>
for event, elem in context :
File "iterparse.pxi", line 491, in lxml.etree.iterparse.__next__ (src/lxml/lxml.etree.c:98565)
File "iterparse.pxi", line 543, in lxml.etree.iterparse._read_more_events (src/lxml/lxml.etree.c:99086)
File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74712)
lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 5, column 1
어떤 아이디어? 고맙습니다!
그것은 XML 파일 형식이 잘못된 것일 수 :
다음 문서는 기존의 코드를 사용하여 올바른 결과를 생산? ' xml' 태그 또는 루트 요소를 포함하지 않습니다. – C0deH4cker
lxml을 모르지만 예제가 유효한 XML이 아닙니다. XML 문서에는 단일 루트 요소가 있어야합니다. 너는 그렇지 않아. –
자식 노드뿐만 아니라 루트 요소가 필요합니다. – pinkdawn