I have the following XML.
I am using ElementTree library to scrape the values.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc> Test1</loc>
</url>
<url>
<loc>Test 2</loc>
</url>
<url>
<loc>Test 3</loc>
</url>
</urlset>
I need to get the values out of 'loc tag'.
Desired Output:
Test 1
Test 2
Test 3
Tried Code:
tree = ET.parse('sitemap.xml')
root = tree.getroot()
for atype in root.findall('url'):
rank = atype.find('loc').text
print (rank)
Any suggestions on where am I wrong ?