parse an XML sitemap with python python

Lasted updated by @craigaddyman on 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 = ""

r = requests.get(url)

data = r.text

soup = BeautifulSoup(data)

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


Subscribe by email