It is the simplest method to submit your sitemap.xml to Google. As, you can submit it without using any Python Google Search console API. This method assumes that you already have a sitemap URL with files that contain a sitemap in XML format.

Step to Follow:

  • Suppose the name of your site is “dummysite.com”, so your sitemap link will be like https://www.dsummysite.com/sitemap.xml or https://www.dsummysite.com/sitemap.xml
  • The next step is to ping your website link, which will help you to avoid any error, in case your website is not working.
  • After ping to your website sitemap link, if you get a response code as 200. You are not ready to ping to google submission link.
  • You need to place the URL of your sitemap’s URL at the end of the ping URL for google. For ex: https://www.google.com/ping?sitemap=https://www.dummysite.com/sitemap.xml

 

Python code to submit the sitemap

import requests

# Make a GET request to your website sitemap link
r = requests.get("https://dummysite.com/sitemap.xml")

print(r.status_code)

# If ping to your site is successful, then ping to google sitemap submission
if r.status_code == 200:
    print("You can now submit XML sitemap")
    r = requests.get("https://www.google.com/ping?sitemap=https://www.dummysite.com/sitemap.xml")
    print(r.text)
    print(r.status_code)