How to Make a Python Sitemap Generator?

In this tutorial, we will use Python 3 and the sitemap-generator library to build a Sitemap Generator. This tool will allow you to crawl your specified website to gather its URLs. After that, it will create an XML file and save all those URLs inside it with the proper XML Sitemap Format.

You can use this Python Sitemap Generator to automate your website/domain sitemap creation process.

You can even provide this tool as an Online Sitemap Generator service. It enables different website owners to generate and download the sitemap.xml file of their website online and place it on their server in no time.

Python Sitemap Generator Source Code Download

pip install sitemap-generator

code.py

import sys
import logging
from pysitemap import crawler

if __name__ == '__main__':
    if '--iocp' in sys.argv:
        from asyncio import events, windows_events
        sys.argv.remove('--iocp')
        logging.info('using iocp')
        el = windows_events.ProactorEventLoop()
        events.set_event_loop(el)

    # root_url = sys.argv[1]
    root_url = 'https://www.edopedia.com'
    crawler(root_url, out_file='sitemap.xml')

Run the Project

python code.py

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.