I suggest you to use lxml to efficiently parse an XML file.
from lxml import etree
Your XML sample is not well-formed, I fixed it like this:
content = """\
<urlset xmlns="http://www.crawlingcourse.com/sitemap/1.3">
<url>
<loc>
http://www.crawlingcourse.com/item-3911512
</loc>
</url>
</urlset>"""
To parse a file, you can use etree.parse(). But since this sample is a string, I use etree.XML():
tree = etree.XML(content)
The natural way to search elements in a XML tree is using XPath. For instance, you can do that:
loc_list = tree.xpath("//url/loc")
But You'll get nothing:
for loc in loc_list:
print(loc.text)
# None
The reason, an it is probably your problem, is that <urlset> use a default namespace: "http://www.crawlingcourse.com/sitemap/1.3".
To make it work, you need to use xpath() function with this namespace. Let's give a name to this namespace: "s":
NS = {'s': "http://www.crawlingcourse.com/sitemap/1.3"}
Then, use the s prefix in your XPath expression like this:
loc_list = tree.xpath("//s:url/s:loc", namespaces=NS)
for loc in loc_list:
print(loc.text)
# http://www.crawlingcourse.com/item-3911512
Because your XML is indented, you need to strip the spaces:
for loc in loc_list:
url = loc.text.strip()
print(url)
# http://www.crawlingcourse.com/item-3911512