편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2021.08.18

    파이썬 오류 xml.etree.ElementTree.ParseError: no element found: line 1, column 0


    다음과 같이 코드를 작성해서 텍스트 파일로 저장하려고 하는데, 저 오류가 떴다가 안 떴다가 하는데 이유가 뭔가요? 어떨 때는 되고 어떨 때는 안 돼서 머리 아프네요.

    def parsingXml(fileName):
    
        import xml.etree.ElementTree as et
        import sys
        import os
        import logging
        logging.basicConfig(format = "%(asctime)s, %(levelname)s: %(message)s", datefmt = "%Y-%m-%d %H:%M:%S %p", level = logging.DEBUG)
    
    
        try:
            sys.stdout = open("C:\\btobl_xml\\{}.txt".format(fileName), "w", encoding = "utf8")
    
        except Exception:
            logging.exception("OUT ERROR")
    
    
        try:
            targetDir = "C:\\btobl_xml"
            fileLIst = os.listdir(targetDir)
            xmlList = []
    
            for file in fileLIst:
                if ".xml" and fileName in file:
                    xmlList.append(file)
    
            for xmlFile in xmlList:
                targetPath = targetDir + "\\" + xmlFile
                root = et.parse(targetPath).getroot()
    
                for tag1 in root:
                    print("-" * 50)
                    print("->", tag1.tag, ":", tag1.text)
                    for tag2 in tag1:
                        print("-->", tag2.tag, ":", tag2.text, tag2.attrib)
                        for tag3 in tag2:
                            print("--->", tag3.tag, ":", tag3.text)
                            for tag4 in tag3:
                                print("---->", tag4.tag, tag4.text, tag4.attrib)
    
    
        except Exception:
            logging.exception("parsing error")
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2021.08.17

    파이썬 오류 xml.etree.ElementTree.ParseError: no element found: line 1, column 0


    다음과 같이 코드를 작성해서 텍스트 파일로 저장하려고 하는데, 저 오류가 떴다가 안 떴다가 하는데 이유가 뭔가요...? 어떨 때는 되고 어떨 때는 안 돼서 머리 아프네요ㅠㅠ

    def parsingXml(fileName):
    
        import xml.etree.ElementTree as et
        import sys
        import os
        import logging
        logging.basicConfig(format = "%(asctime)s, %(levelname)s: %(message)s", datefmt = "%Y-%m-%d %H:%M:%S %p", level = logging.DEBUG)
    
    
        try:
            sys.stdout = open("C:\\btobl_xml\\{}.txt".format(fileName), "w", encoding = "utf8")
    
        except Exception:
            logging.exception("OUT ERROR")
    
    
        try:
            targetDir = "C:\\btobl_xml"
            fileLIst = os.listdir(targetDir)
            xmlList = []
    
            for file in fileLIst:
                if ".xml" and fileName in file:
                    xmlList.append(file)
    
            for xmlFile in xmlList:
                targetPath = targetDir + "\\" + xmlFile
                root = et.parse(targetPath).getroot()
    
                for tag1 in root:
                    print("-" * 50)
                    print("->", tag1.tag, ":", tag1.text)
                    for tag2 in tag1:
                        print("-->", tag2.tag, ":", tag2.text, tag2.attrib)
                        for tag3 in tag2:
                            print("--->", tag3.tag, ":", tag3.text)
                            for tag4 in tag3:
                                print("---->", tag4.tag, tag4.text, tag4.attrib)
    
    
        except Exception:
            logging.exception("parsing error")