20 lines
518 B
Python
20 lines
518 B
Python
from bs4 import BeautifulSoup
|
|
|
|
fields = None
|
|
with open('income-scraped-to-xml.xml') as xmlfile:
|
|
|
|
xmlread = xmlfile.read()
|
|
|
|
soup = BeautifulSoup(xmlread, features='xml')
|
|
|
|
# Start file
|
|
f = open('xml-back-to-csv.csv', 'w')
|
|
|
|
# Write rows to file
|
|
f.write(",".join(['famindex', 'AGE', 'FTOTINC'])+'\n')
|
|
rows = soup.findAll('row')
|
|
for row in rows:
|
|
f.write(','.join([row.famindex.string, row.AGE.string, row.FTOTINC.string])+'\n')
|
|
|
|
# Close file
|
|
f.close() |