Simple XML Sitemap Creation Through Python

Simple XML Sitemap Creation Through Python

XML sitemaps are beneficial for the discovery of URLs by Google. Some online free tools let you create XML sitemaps, but usually have a limitation to 500 URLs or so. On the other hand, other paid tools can assist you to create an extra-large sitemap. Here, Python can play an important role to help you create XML sitemaps for SEO.

xml file creation with python

In this blog post, we will show you how to create a sitemap.xml file using Python with each and every step mentioned.

For prerequisites, you can refer to this blog steps for implementation step by step.

Once you are done with this, then head over to the Anaconda console, to run the command as shown below:

Code 1: pip install oauth2client httplib2

Code 2: pip install pandas

Here we need to install some library files, as shown below:

Code 1 initialization done

Code 2 initialization done

Now just check the current index status for the site you are expecting to index on Google.

Current discovered URLs on Google: 634

And based on these searches, make a comprehensive list of URLs that you want to index on Google and save it in a CSV file (data.csv)

Then create a folder consisting of 2 files, one is data.csv (the list of URLs), another one is code snippet file.

Once you are ready with all the files then we need to finally run the indexing script through the terminal as shown here:

Let’s run the code of

We re-run the Anaconda Console and change the path of the respective directory by putting the below syntax as shown in the screenshot below:

After changing the path we run the following code as below:

Code to execute: python

Once you run the code Google will get the indexing request for the specified URLs with timestamps as shown in the above screenshot.

After executing the code the sitemap_0.xml zip file is created.

The Sitemap file is properly included on all the pages.