I am trying to check if an element has an other element inside. the url element sometime contain loc tag alone and sometimes loc and image tag, i want to get the value of the loc tag when there is an image tag as well, i tried something like this.
url = "https://www.aeroprecisionusa.com/media/sitemap_en.xml"
response = requests.get(url)
root = ET.fromstring(response.content)
links = []
for elm in root.findall(".//{http://www.sitemaps.org/schemas/sitemap/0.9}url"):
if elm.find('.//{http://www.sitemaps.org/schemas/sitemap/0.9}image) is not None:
link = elm.find('./{http://www.sitemaps.org/schemas/sitemap/0.9}loc').text
links.append(link)
return links
but still it returns loc tag of all url parent element.