Head of Digital Marketing @Bronco. Lover of Python and Data.

Parse An Xml Sitemap With Python

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


Give Your Inbox Some Love


What You'll get?
  • Posts like this delivered straight to your inbox!
  • Nothing else.
Comment Policy

Any code snippets more than a line or 2, please include as a link to a gist

comments powered by Disqus