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.