Last Updated: 20-August-2015

I have had parse a number of XML sitemaps this week for different reasons so I thought I would make it a little easier and quicker. There are specific standard libraries for parsing XML but this is what I came up with...


from bs4 import BeautifulSoup
import requests

url = "http://www.site.co.uk/sitemap.xml"

r = requests.get(url)

data = r.text

soup = BeautifulSoup(data)

for url in soup.findAll("loc"):
    print url.text

About the author

Image

Craig Addyman @craigaddyman
Head of Digital Marketing. Python Coder.