streamlit app that takes any sitemap xml or url and generates a CSV of all urls
Drop files here
or click to upload
import streamlit as st
import requests
import xmltodict
import pandas as pd
st.title("Sitemap to CSV Generator")
# Input field for sitemap URL
sitemap_url = st.text_input("Enter Sitemap URL or upload XML file:")
if sitemap_url:
try:
# Fetch the sitemap XML
if sitemap_url.startswith('http'):
response = requests.get(sitemap_url)
sitemap_content = response.content
else:
with open(sitemap_url, 'r') as file:
sitemap_content = file.read()
# Parse the XML content
sitemap_dict = xmltodict.parse(sitemap_content)
urls = []
# Extract URLs from the parsed dictionary
if 'urlset' in sitemap_dict:
for url in sitemap_dict['urlset']['url']:
urls.append(url['loc'])
# Create a DataFrame and display the URLs
df = pd.DataFrame(urls, columns=["URLs"])
st.write("### Extracted URLs:")
st.table(df)
# Provide a download link for the CSV
csv = df.to_csv(index=False)
st.download_button("Download CSV", csv, "sitemap_urls.csv", "text/csv")
except Exception as e:
st.error(f"An error occurred: {e}")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?