Created
February 18, 2019 14:23
-
-
Save rupython/1e07a3b33c7d58c2ebef2f57595d587f to your computer and use it in GitHub Desktop.
From: Ulan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Created on Mon Feb 18 18:14:02 2019 | |
| @author: rocket | |
| """ | |
| import os | |
| import xml.etree.ElementTree as ET | |
| def getBatchNameFromXML(XML_path): | |
| """ | |
| <catalog> главная ветка | |
| <book id="bk101"> | |
| <author>Gambardella, Matthew</author> | |
| <title>XML Developer's Guide</title> | |
| </book> | |
| <catalog/> | |
| """ | |
| try: | |
| tree = ET.parse(XML_path) | |
| catalog = tree.getroot() | |
| batches = catalog.find("book") # тег который мы ищем в основной ветке | |
| batch = batches[0].attrib | |
| name = batch.get("author") | |
| return name | |
| except IOError as e: | |
| print (e) | |
| path_to_program = "/home/rocket/parserxml" | |
| data_directory = "/DATA" | |
| path_to_XML = path_to_program + data_directory + "/XML/" | |
| files_list = os.listdir(path_to_XML) | |
| all_batch_Names = [] | |
| for file in files_list: | |
| all_batch_Names.append(getBatchNameFromXML(path_to_XML + file)) | |
| print(all_batch_Names) | |
| print (getBatchNameFromXML(path_to_XML + file)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment