I have this sitemap in xml. How i can get each <loc>
?
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->
<url>
<loc>https://www.nsnam.org/wiki/Main_Page</loc>
<lastmod>2018-10-24T03:03:05+00:00</lastmod>
<priority>1.00</priority>
</url>
<url>
<loc>https://www.nsnam.org/wiki/Current_Development</loc>
<lastmod>2018-10-24T03:03:05+00:00</lastmod>
<priority>0.80</priority>
</url>
<url>
<loc>https://www.nsnam.org/wiki/Developer_FAQ</loc>
<lastmod>2018-10-24T03:03:05+00:00</lastmod>
<priority>0.80</priority>
</url>
Program looks like this.
import os.path
import xml.etree.ElementTree
import requests
from subprocess import call
def creatingListOfBrokenLinks():
if (os.path.isfile('sitemap.xml')):
e = xml.etree.ElementTree.parse('sitemap.xml').getroot()
file = open("all_broken_links.txt", "w")
for atype in e.findall('url'):
r = requests.get(atype.find('loc').text)
print(atype)
if (r.status_code == 404):
file.write(atype)
file.close()
if __name__ == "__main__":
creatingListOfBrokenLinks()