I am trying to cover 1 XML file to CSV/xls. I have tried below code but seems not working. I have to fetch CentreFrequency for "NodeName" whose Role = Base. Below is the sample XML https://pastebin.com/Ln4Ug0hN
from bs4 import BeautifulSoup
import pandas as pd
import lxml
import xml.etree.cElementTree
import openpyxl
import inspect
import os
import tkinter
from tkinter import filedialog
root = tkinter.Tk()
dirname = filedialog.askopenfilename(parent=root, initialdir="/",
title='Please select a file')
root = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
sites = "xmll.xml"
with open(sites, "r",encoding='unicode_escape') as f:
xml_data = f.read()
soup = BeautifulSoup(xml_data, "xml")
#ss=soup.find_all("NodeName").text
# 'INAPKVLIVGLRTW6001ENBIB5004'
tag1 = input("Enter tagname1:")
tag2 = input("Enter tagname2:")
# in a loop
data = []
dd = []
for td in soup.find_all(tag1):
data.append({"Name": td.text})
for snmp in soup.find_all(tag2):
dd.append({"CentreFrequency": snmp.text})
df1 = pd.DataFrame(data)
df2 = pd.DataFrame(dd)
df = pd.merge(df1,df2,left_index=True, right_index=True)