streamlit app that takes any sitemap xml url and makes a CSV
Drop files here
or click to upload
import streamlit as st
import requests
import pandas as pd
from lxml import etree
st.title('Sitemap to CSV Converter')
# Input for the Sitemap URL
sitemap_url = st.text_input('Enter Sitemap XML URL:')
if sitemap_url:
try:
# Fetch the sitemap XML
response = requests.get(sitemap_url)
response.raise_for_status() # Raise an error for bad responses
xml_content = response.content
# Parse the XML content
root = etree.fromstring(xml_content)
# Extract URLs from the sitemap
namespace = {'ns': 'http://www.sitemaps.org/schemas/sitemap-image/'}
urls = [url.text for url in root.xpath('//ns:url/ns:loc', namespaces=namespace)]
# Create a DataFrame
df = pd.DataFrame(urls, columns=['URL'])
# Button to download CSV
csv = df.to_csv(index=False)
st.download_button(label='Download CSV', data=csv, file_name='sitemap.csv', mime='text/csv')
except Exception as e:
st.error(f'Error: {e}')
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?